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

Support positional-only arguments in #[pyfunction] #1439

Closed
davidhewitt opened this issue Feb 20, 2021 · 1 comment · Fixed by #1925
Closed

Support positional-only arguments in #[pyfunction] #1439

davidhewitt opened this issue Feb 20, 2021 · 1 comment · Fixed by #1925

Comments

@davidhewitt
Copy link
Member

davidhewitt commented Feb 20, 2021

I noticed this morning that we don't yet have support for Python 3.8's positional-only arguments (PEP 570). This should be a nice standalone feature which anyone interested is welcome to implement. I can help mentor with any questions.

Some examples of how they interact:

>>> def foo(a, /, b):
...     print(a, b)
...
>>> foo(1, 3)
1 3

>>> foo(a=1, b=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got some positional-only arguments passed as keyword arguments: 'a'

# Also combines with keyword-only separator
>>> def foo(a, /, *, b):
...     print(a, b)
...
>>> foo(1, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() takes 1 positional argument but 2 were given

This will need changes in a couple of places:

  • The proc macro code will need to be extended to support positional-only arguments. A starting-point would be to teach add_literal which already parses "*" to also parse "/".
  • The runtime code to parse_fn_args will need adjusting to handle these positional-only arguments.

Both parts of the code are welcome to be refactored at the same time to deal with the additional complexity.

@davidhewitt
Copy link
Member Author

The argument extraction was updated in #1440 so now we just need to add this to our macros!

@aganders3 aganders3 mentioned this issue Oct 17, 2021
8 tasks
@davidhewitt davidhewitt linked a pull request Oct 17, 2021 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant