Skip to content

Basic isinstance() type inference #245

Closed
@JukkaL

Description

@JukkaL

The type checker should know about isinstance checks. For example, this code should be valid:

def f(x: object) -> None:
    if isinstance(x, str):
        # x has type str here.
        print(x + 'foo')  # ok

Initially only support cases where the first argument is a variable and the 'if' condition only contains an isinstance check. Later, consider extending this to more complex cases.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions