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

Improve support for positional-only arguments #2706

Closed
Zac-HD opened this issue Dec 19, 2020 · 3 comments · Fixed by #3389
Closed

Improve support for positional-only arguments #2706

Zac-HD opened this issue Dec 19, 2020 · 3 comments · Fixed by #3389
Labels
enhancement it's not broken, but we want it to be better

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Dec 19, 2020

#2218 proposed that we should "consider replacing uses of inspect.getfullargspec() with inspect.signature()" after dropping support for Python 2, which would also help with #2495. With the increasing adoption of positional-only arguments (PEP 570, Python 3.8 and later), I think this has only become more urgent.

The main concern is our @proxies() decorator, which wraps end-user code in a variety of places... and silently breaks positional-only arguments because they're unsupported by our internal define_function_signature(). In particular, this affects @st.composite and stateful testing methods.

Secondary concerns include @given() (currently restricted to args-xor-kwargs, which reduces impact), or our st.builds() and Django from_model() strategies (current workarounds are fine, but don't work with true pos-only arguments after we drop Python 3.7).

@Zac-HD Zac-HD added the enhancement it's not broken, but we want it to be better label Dec 19, 2020
@Zac-HD
Copy link
Member Author

Zac-HD commented Dec 31, 2021

Working 80/20 prototype, covering @proxies() but not @given(): master...Zac-HD:use-signature

This could be shipped as-is without breaking anything that currently works, but I want to write some tests for use of positional-only args in @st.composite, etc., before that so that we can see that it really does improve things.

While not relevant until we drop Python 3.7, this also means the obvious approach of replacing our pos-only workarounds in st.builds() and from_model() with true pos-only arguments will just work.

@Zac-HD
Copy link
Member Author

Zac-HD commented Jun 28, 2022

def execute_explicit_examples(state, wrapped_test, arguments, kwargs):

Oh dear. It turns out that the arguments argument is... entirely ignored when executing explicit examples, which means that varargs aren't passed in at all. On the other hand, test_vararg_output notwithstanding, since it's broken we can replace it without violating backwards compatibility 😓

(the replacement being "do the same thing as we do for all the generated/non-explicit examples")

@Zac-HD
Copy link
Member Author

Zac-HD commented Jun 30, 2022

Having dug into this, I'm going to keep positional-only arguments in a function wrapped by @given() explicitly banned as a confusing footgun, but they should work everywhere else.

(later update: subsequent work allows @given(**kw) to wrap a function with positional-only arguments, but not @given(*args))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant