Skip to content
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

Merged
merged 1 commit into from
Jun 21, 2023

Conversation

bluetech
Copy link
Member

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.

Copy link
Member

@nicoddemus nicoddemus left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Member

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.

Suggested change
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.

Copy link
Member Author

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.

Copy link
Member

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()
Copy link
Member

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.

class hello:
@hookimpl(wrapper=True, hookwrapper=True)
def he_method1(self):
yield
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
@bluetech bluetech merged commit 8103269 into pytest-dev:main Jun 21, 2023
@bluetech bluetech deleted the new-style-v2 branch June 21, 2023 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Require new-style hooks to also be marked as hook-wrappers
2 participants