Skip to content

Missing conformance tests around nonlocal rebinding of type params from annotation scopes #1921

@samwgoldman

Description

@samwgoldman

The language reference mentions this restriction:

Names defined in annotation scopes cannot be rebound with nonlocal statements in inner scopes. This includes only type parameters, as no other syntactic elements that can appear within annotation scopes can introduce new names.

I noticed that Pyright doesn't implement this restriction, while Mypy does.

def f[Ty](x: Ty) -> Ty:
    nonlocal Ty
    y: Ty = x
    Ty: int = 0
    return y

[Pyright Playground] [Mypy Playground]

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: otherOther topics not covered

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions