-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make new-style wrappers use explicit wrapper=True
#411
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Left a few comments.
docs/index.rst
Outdated
be called to *wrap* (or surround) all other normal *hookimpl* calls. A *hook | ||
wrapper* can thus execute some code ahead and after the execution of all | ||
corresponding non-wrappper *hookimpls*. | ||
A *hookimpl* can be marked with the ``"hookwrapper"`` option, which indicates |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A *hookimpl* can be marked with the ``"hookwrapper"`` option, which indicates | |
A *hookimpl* can be marked with the ``"wrapper"`` option, which indicates |
docs/index.rst
Outdated
@@ -368,17 +368,17 @@ Wrappers | |||
1.1. For earlier versions, see the "old-style hook wrappers" section below. | |||
The two styles are fully interoperable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should mention the distinct option names next to each other, as this will help users search for them and be told of the difference explicitly.
The two styles are fully interoperable. | |
New-style hooks wrappers are declared with ``wrapper=True``, while old-style hook wrappers are declared with ``hookwrapper=True`` (for backward compatibility). | |
The two styles are fully interoperable between plugins using different styles. However within the same plugin we recommend using only one style, for consistency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll apply this, except for the "(for backward compatibility)" part, I think it is potentially confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh right, might give the impression we are deprecating old-style hook wrappers, which is not the case.
class Api: | ||
@hookspec | ||
def hello(self) -> Iterator[int]: | ||
raise NotImplementedError() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add raise NotImplementedError
to .coveragerc
as a line to be excluded from coverage.
testing/test_pluginmanager.py
Outdated
class hello: | ||
@hookimpl(wrapper=True, hookwrapper=True) | ||
def he_method1(self): | ||
yield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yield | |
yield # pragma: no cover |
Previously new-style wrappers were implied by the function being a generator, however that broke a use case of a non-wrapper impl being a generator as a way to return an Iterator result. This is legitimate, and used at least by conda (see pytest-dev#403). Therefore, change to require an explicit `wrapper=True`. Also adds a test for the iterator-returning case. Fix pytest-dev#405.
Previously new-style wrappers were implied by the function being a generator, however that broke a use case of a non-wrapper impl being a generator as a way to return an Iterator result. This is legitimate, and used at least by conda (see #403).
Therefore, change to require an explicit
wrapper=True
. Also adds a test for the iterator-returning case.Fix #405.