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 authored Sep 27, 2024
1 parent 24895d0 commit 0fcbb07
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,15 @@ 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

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

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L195

Added line #L195 was not covered by tests
method: object = getattr(plugin, name)
try:
method: object = getattr(plugin, name)
except AttributeError:

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

View check run for this annotation

Codecov / codecov/patch

src/pluggy/_manager.py#L198

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

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

0 comments on commit 0fcbb07

Please sign in to comment.