Conversation
bluetech
force-pushed
the
hookspec-defaults
branch
from
September 19, 2026 11:01
02e9bcb to
a031c1c
Compare
RonnyPfannschmidt
approved these changes
Sep 19, 2026
RonnyPfannschmidt
left a comment
Member
There was a problem hiding this comment.
my key nitpick form last time is that i only ever wanted to allow none as sentinel/default in order to prevent some types of drift
but i recon that this might have been too pedantic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This is mainly a backward compatibility feature, to allow a hookspec to add new parameters to an existing hook without breaking existing callers.
The immediate motivation for this is coming from pytest-dev/pytest#15035, where pytest wants to add an argument to
pytest_deselecthook but there are many existing external callers.This feature has been discussed and implemented before:
although I haven't been able to figure out why it was rejected. To me it seems like an intuitive and natural feature, so I decided to put forward another attempt :)
The call overhead when default is not declared is a function call + 2 ifs, which seems OK to me. (Potentially can inline
_apply_defaultsbut I still hold hope that cpython will one day do such trivial optimizations itself).Note: there is a separate matter with defaults declared by hookimpls, which I think currently behave in an unintuitive way. There's an issue for it #442. I will try to tackle it next, as it has some interaction with this feature (see
test_does_not_override_hookimpl_defaulttest in this PR), but it's preexisting.Fix #170.