Skip to content

Final qualifier for unpacked values? #705

@Tatsh

Description

@Tatsh

I looked at PEP 591 and saw no mention of unpacking.

Currently (AFAIK) there does not appear to be a way to make unpacked variables Final, either inline or by declaring variables first. Some lines which look like they might work but don't:

x: Final, y: Final = True, False

(x, y): Final = True, False  # *only single target (not tuple) can be annotated  [syntax]*

x, y: Final = True, False  # syntax error, confusing

(x, y) = Final[(True, False)]  # syntax ok but x and y inferred by Mypy as Any, error at runtime

Of course the first is very verbose and usually you wouldn't want to have one value be final and another not when unpacking.

The second makes some sense except it would be nice to retain the optional parentheses feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions