Skip to content

Implement class instantiation handling #186

@mishamsk

Description

@mishamsk

Description

Currently red knot assumes all calls to class literals are valid and create instances. E.g. this test yields no diagnostic currently

from typing import Literal

class Number:
    def __init__(self, value: int):
        self.value = 1

    def __pos__(self) -> int:
        return +self.value

    def __neg__(self) -> int:
        return -self.value

    def __invert__(self) -> Literal[True]:
        return True

a = Number()

We should check __init__ signature just like any other call and emit diagnostics.

This is step 1 in a series of feature to support the instance creation process in full. The related logic of handling type[C] is tracked in astral-sh/ruff#15948

Metadata

Metadata

Assignees

Labels

callsIssues relating to call-signature checking and diagnostics

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions