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 signature
so that we support positional-only arguments
#3241
Conversation
e290bb1
to
e8730ad
Compare
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.
Had to familiarise myself more with the reflection stuff so yeah, but LGTM! Excited for pos-only adoption.
@@ -22,8 +22,10 @@ | |||
from tokenize import detect_encoding | |||
from types import ModuleType | |||
from typing import TYPE_CHECKING, Callable | |||
from unittest.mock import _patch as PatchType |
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.
Unfortunate unittest
doesn't expose this publicly, but I guess this has and will remain pretty stable.
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.
Yeah, our internals do (have to) depend on a lot of technically-private stuff. Best mitigation is extensive testing, including on alpha versions of new Python releases - if something breaks we should find out far enough in advance to fix it before the stable release.
@@ -90,7 +90,7 @@ def __init__(self, grammar, start, explicit): | |||
# This is a total hack, but working around the changes is a nicer user | |||
# experience than breaking for anyone who doesn't instantly update their | |||
# installation of Lark alongside Hypothesis. | |||
compile_args = getfullargspec(grammar.grammar.compile).args | |||
compile_args = signature(grammar.grammar.compile).parameters |
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 changing this to signature(grammar.grammar.compile, follow_wrapped=False).parameters
will preserve parity with getfullargspec(grammar.grammar.compile).args
/ will address #3245
@@ -1463,29 +1467,32 @@ def composite(f: Callable[..., Ex]) -> Callable[..., SearchStrategy[Ex]]: | |||
else: | |||
special_method = None | |||
|
|||
argspec = getfullargspec(f) | |||
sig = signature(f) |
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.
To preserve behavior of getfullargspec
:
sig = signature(f) | |
sig = signature(f, follow_wrapped=False) |
): | ||
defaults[name] = value | ||
if len(argspec.args) > 1 or argspec.defaults: | ||
sig = signature(self.function) |
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.
sig = signature(self.function) | |
sig = signature(self.function, follow_wrapped=False) |
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.
(there are additional instances below, but I'll hold off on pointing them all out in case I am simply wrong here)
I think we actually do want the new behaviour here, and it's on pytest-asyncio for using our internals to update. |
Fair enough! This caused an error in MyGrad's test suite, but only because I was using |
This patch addresses about two-thirds of #2706 - notably,
@st.composite
strategies may now use positional-only arguments, which were added in Python 3.8, andst.builds()
and the Django extra'sfrom_model()
are now true positional-only argumentsThis is basically just a nice cleanup to have; for API clarity I don't intend to support nontrivial signatures in
@given()
-wrapped tests. That's also some scary core code, so I'm leaving the relevant no-user-impact refactoring in there for later.