Skip to content

Commit

Permalink
Update _manager.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pirate authored Sep 27, 2024
1 parent 92a2f63 commit 9d8d198
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,17 @@ def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> HookimplOpts | None
options for items decorated with :class:`HookimplMarker`.
"""

# IMPORTANT: accessing an @property can have side effects that we dont want to trigger
# if attr is a property, skip it in advance (@property methods can never be hookimpls)
# IMPORTANT: @property methods can have side effects, and are never hookimpl
# if attr is a property, skip it in advance
plugin_class = plugin if inspect.isclass(plugin) else type(plugin)
if isinstance(getattr(plugin_class, name, None), property):
return None

# if attr is field on a pydantic model, skip it (pydantic fields are never hookimpls)
if hasattr(plugin, "__pydantic_core_schema__") and name in getattr(
plugin, "model_fields", {}
):
# pydantic can present class attributes, instance attributes, or methods
# but none of them can be hookimpls so they throw off the logic below
# pydantic model fields are like attrs and also can never be hookimpls
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)
Expand Down

0 comments on commit 9d8d198

Please sign in to comment.