Skip to content

False positive when assigning to Final instance attribute in __init__ #1409

@sharkdp

Description

@sharkdp

From the conformance suite (and 44 instances across the ecosystem once type-of-self lands):

from typing import Final, Self

class ClassA:
    ID4: Final[int]  # OK because initialized in __init__

    def __init__(self: Self):
        self.ID4 = 1  #     Cannot assign to final attribute `ID4` on type `Self@__init__` (invalid-assignment)

https://play.ty.dev/38bf9854-4d2e-495c-b96b-29553d212819

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtype propertiessubtyping, assignability, equivalence, and more

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions