Skip to content

Support for positional only parameters/arguments def f(a, /, b, *, c) #8362

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

Open
michalpokusa opened this issue Sep 4, 2023 · 1 comment

Comments

@michalpokusa
Copy link

CPython supports so called positional only parameters (PEP 570) with as the name say, cannot be passed using their name.
They are useful when a function e.g. accepts a value that has not special meaning, it is simply a value.

Example:

def some_function(positional_only, /, positional_or_keyword, *, keyword_only):
    pass

some_function(1, 2, keyword_only=3)
some_function(1, positional_or_keyword=2, keyword_only=3)

Expected output:


Actual output:

Traceback (most recent call last):
  File "code.py", line 19, in <module>
  File "src/hid_testing.py", line 5
SyntaxError: invalid syntax

What is interesting, there seems to already be a implementation of this in CircuitPython in some way, as e.g. a built-in abs() works that way:

image

>>> abs(-3.5)
3.5
>>> abs(__x=-3.5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function doesn't take keyword arguments
>>>
@dhalbert
Copy link
Collaborator

dhalbert commented Sep 4, 2023

There is is some work already on this in MicroPython: micropython#8480. We would probably wait for this to be finished and then merge it.

@dhalbert dhalbert added this to the Long term milestone Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants