Skip to content

Commit

Permalink
Add exception handler to deal with proxy object attrs as well
Browse files Browse the repository at this point in the history
  • Loading branch information
pirate committed Sep 27, 2024
1 parent 24895d0 commit aae3799
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,16 @@ def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> HookimplOpts | None
# pydantic model fields are like attrs and also can never be hookimpls

Check warning on line 191 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L191

Added line #L191 was not covered by tests
plugin_is_pydantic_obj = hasattr(plugin, "__pydantic_core_schema__")
if plugin_is_pydantic_obj and name in getattr(plugin, "model_fields", {}):
# pydantic models mess with the class and attr __signature__
# so inspect.isroutine(...) throws exceptions and cant be used
return None

method: object = getattr(plugin, name)
method: object

Check warning on line 196 in src/pluggy/_manager.py

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L195-L196

Added lines #L195 - L196 were not covered by tests
try:
method = getattr(plugin, name)
except AttributeError:
# AttributeError: '__signature__' attribute of 'Plugin' is class-only
# can happen for some special objects (e.g. proxies, pydantic, etc.)
method = getattr(type(plugin), name) # use class sig instead

if not inspect.isroutine(method):
return None
try:
Expand Down

0 comments on commit aae3799

Please sign in to comment.