-
Notifications
You must be signed in to change notification settings - Fork 588
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
Use ParamSpec
to precisely annotate @st.composite
and st.functions()
#3396
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RELEASE_TYPE: minor | ||
|
||
This release uses :pep:`612` :obj:`python:typing.ParamSpec` (or the | ||
:pypi:`typing_extensions` backport) to express the first-argument-removing | ||
behaviour of :func:`@st.composite <hypothesis.strategies.composite>` | ||
and signature-preservation of :func:`~hypothesis.strategies.functions` | ||
to IDEs, editor plugins, and static type checkers such as :pypi:`mypy`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ class ConstructivePredicate(NamedTuple): | |
predicate: Optional[Predicate] | ||
|
||
@classmethod | ||
def unchanged(cls, predicate): | ||
def unchanged(cls, predicate: Predicate) -> "ConstructivePredicate": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If some class will subclass We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a private/internal-only class and so should never be subclassed; I'd decorate it with |
||
return cls({}, predicate) | ||
|
||
|
||
|
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.
I think that it is safe to say that we cannot currently annotate this with
ParamSpec
, because of how complex its argument addition is.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.
Alas, yes, it's a partial-bind of only positional-or-keyword xor keyword-only parameters; and you can't pass strategies as positional args if there are any pos-only parameters; and positional args are bound from the rightmost pos-or-kw parameter (bizzare semantics, but we're stuck with it now).
I don't even see a more-precise overload we could extract, the closest would be "if you pass all the kwargs the wrapped function accepts, then the new function has no parameters", but even that breaks with
**kwargs
.