Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

inspect.Parameter checks thatname is an identifier, but does not check for keywords #92062

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
@Zac-HD

Description

@Zac-HD

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp