Skip to content

Conformance: test that @override checks are honored for __init__ / __new__ #2222

@randolf-scholz

Description

@randolf-scholz

When explicitly marking a method with @override, type checkers ought to test assignability (https://typing.python.org/en/latest/spec/class-compat.html#override).

Hence, even methods like __init__ and __new__, which are normally not checked against their parent classes, should be checked when explicilty decorated with @override.

from typing import override

class Foo:
    def __init__(self, x: int) -> None: ...

class Bar(Foo):
    @override
    def __init__(self, y: int) -> None: ...  # should error

This is useful in cases when we really need constructors to be compatible.
I suggest adding a version of the example above to the conformance test suite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions