Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Consider the following code:
defsend(from): ...
Thisparses, but it doesn't compile:from is a keyword and so the code is syntactially invalid.
The problem is thatinspect.Parameter checks that the given name is anidentifier, but doesn't check that it'snot a keyword. You can thus create invalid signatures, which cause considerable confusion on downstream introspection:
deff(source):passfrominspectimportSignature,Parameterf.__signature__=Signature([Parameter("from",P.KEYWORD_ONLY)],return_annotation=None)# Or, as the real-world motivation,classModel(pydantic.BaseModel):source:None=pydantic.Field(None,alias="from")
We're fixing this downstream inHypothesisWorks/hypothesis#3317 andpydantic/pydantic#4012, but I think thatinspect.Parameter("from", ...) should also raise an error, just as if the provided name was not an identifier at all.