Skip to content

Commit 1407cba

Browse files
authored
Avoid triggering property methods when inspecting plugin attribute signatures
1 parent b2cf1ff commit 1407cba

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/pluggy/_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ def parse_hookimpl_opts(self, plugin: _Plugin, name: str) -> HookimplOpts | None
181181
customize how hook implementation are picked up. By default, returns the
182182
options for items decorated with :class:`HookimplMarker`.
183183
"""
184+
185+
# IMPORTANT: accessing an @property can have side effects that we dont want to trigger
186+
# if attr is a property, skip it in advance (@property methods can never be hookimpls)
187+
plugin_class = plugin if inspect.isclass(plugin) else type(plugin)
188+
if isinstance(getattr(plugin_class, name, None), property):
189+
return None
190+
191+
# if attr is field on a pydantic model, skip it (pydantic fields are never hookimpls)
192+
if hasattr(plugin, '__pydantic_core_schema__') and name in getattr(plugin, 'model_fields', {}):
193+
# pydantic can present class attributes, instance attributes, or methods
194+
# but none of them can be hookimpls so they throw off the logic below
195+
return None
196+
184197
method: object = getattr(plugin, name)
185198
if not inspect.isroutine(method):
186199
return None

0 commit comments

Comments
 (0)