Skip to content

Commit

Permalink
Avoid triggering property methods when inspecting plugin attribute si…
Browse files Browse the repository at this point in the history
…gnatures
  • Loading branch information
pirate authored Sep 27, 2024
1 parent b2cf1ff commit 1407cba
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,19 @@ def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> HookimplOpts | None
customize how hook implementation are picked up. By default, returns the
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)
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
return None

method: object = getattr(plugin, name)
if not inspect.isroutine(method):
return None
Expand Down

0 comments on commit 1407cba

Please sign in to comment.