Make new-style wrappers use explicit wrapper=True#411
Make new-style wrappers use explicit wrapper=True#411bluetech merged 1 commit intopytest-dev:mainfrom
wrapper=True#411Conversation
nicoddemus
left a comment
There was a problem hiding this comment.
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.
| 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.
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.
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.
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.
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.
| 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.