Skip to content

Allow setting final instance attributes in __new__ #5774

Open
@ilevkivskyi

Description

@ilevkivskyi

These patterns should be allowed:

class C:
    def __new__(cls, x: int) -> C:
        self = object.__new__(cls)
        self.x: Final = x
        return self

and

class C:
    x: Final[int]
    def __new__(cls) -> C:
        self = object.__new__(cls)
        self.x: Final = 1
        return self

Currently this is blocked by #1021

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions