Repository navigation
Discover hooks via inspect.getattr_static - #701
Merged
RonnyPfannschmidt merged 11 commits intoSep 12, 2026
Merged
RonnyPfannschmidt merged 11 commits into
RonnyPfannschmidt merged 11 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written with AI assistance (Cursor, then Claude Code). I reviewed it and I am posting it.
Plugin registration used
getattr()to find hookimpls, which executes every property and descriptor on the object just to look for markers. That is a side effect nobody asked for, and it falls over on objects whose attribute access raises.This switches discovery to
inspect.getattr_static(). Only plain functions,classmethod,staticmethodand bound methods are considered hookable; properties,cached_propertyand other descriptors are skipped without being evaluated.Binding semantics
Discovery reproduces what
getattr()would have returned, rather than replacing it:__dict__or in a__slots__slot — is also returned unbound, becausegetattr()does not run the descriptor protocol on instance storage. A hookimpl assigned in__init__keeps its declared signature and gets no implicitself;classmethod/staticmethodare bound via__get__after the scan instead of during it.Thanks to @copilot for catching the instance-
__dict__case in review; the__slots__variant, which silently dropped the hook altogether, turned up while fixing it. Both are covered by tests now.Marker placement
One thing falls out of the static lookup:
@hookimplapplied above@classmethod/@staticmethodnow works. The marker sits on the wrapper, which the oldgetattr()path never saw, so those hooks were silently missed when registering an instance.Notes
Supersedes #536, which addressed the property case by special-casing
AttributeError. This branch is rebased onmainand stands on its own — #536 can be closed once this lands.src/pluggy/_manager.pyis at 100% statement and branch coverage with these tests. pytest's own test suite passes unchanged against this branch (4554 passed).🤖 Generated with Claude Code