Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
While working on #103553 I found one more problem that merits its own issue.
Right now it is impossible to create a function that have a pos-or-keyword parameter without a default comming after a pos-only parameter with a default. Demo:
>>>deftest(pod=42, /, pk): ... File"<stdin>", line1deftest(pod=42, /, pk): ... ^^SyntaxError: parameterwithoutadefaultfollowsparameterwithadefault>>>lambdapod=42, /, pk: ... File"<stdin>", line1lambdapod=42, /, pk: ... ^^SyntaxError: parameterwithoutadefaultfollowsparameterwithadefaultBut, it is possible to create a signature like this. Repro:
>>>importinspect>>>defone(pk): ... ... >>>deftwo(pod=42, /): ... ... >>>sig1=inspect.signature(one) >>>sig2=inspect.signature(two) >>>inspect.Signature((sig2.parameters['pod'], sig1.parameters['pk'])) <Signature (pod=42, /, pk)>This looks like a bug to me, there's no reason for a signature to behave differently and to support function signatures that cannot be created.
Desired behaviour:
Traceback (mostrecentcalllast): File"/Users/sobolev/Desktop/cpython/ex.py", line7, in<module>print(inspect.Signature((sig2.parameters['pod'], sig1.parameters['pk']))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/Users/sobolev/Desktop/cpython/Lib/inspect.py", line3039, in__init__raiseValueError(msg) ValueError: non-defaultargumentfollowsdefaultargumentThe fix is quite easy. PR is incomming.
I've also tried the same thing with #103404 (because it is very related) but, it still does not solve this corner case.
Linked PRs
Gouvernathor
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error