Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy