Skip to content

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

Open
@michalpokusa

Description

@michalpokusa

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
>>>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions