Skip to content

[red-knot] Attributes implicitly declared via their parameter types #15960

@sharkdp

Description

@sharkdp

The idea of this ticket is to support the following use case.

class C:
    def __init__(self, x: int | None):
        self.x = x

reveal_type(C().x)  # Should be `int | None`, is currently `Unknown | int | None`

We have pre-existing tests with TODO comments for this scenario. The goal of this issue it to get rid of these (there are more TODOs that would be resolved by this feature):

# TODO: should be `int | None`
reveal_type(c_instance.inferred_from_param) # revealed: Unknown | int | None

Part of: #14164

Metadata

Metadata

Assignees

Labels

help wantedContributions especially welcometyMulti-file analysis & type inference

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions