KotlinIsland / KotlinIsland/basedmypy

Infer exact types

Open
#202 3 comments 0 reactions 0 assignees View on GitHub
feature p-1 strict-equality
Dominant language
Python
Stars
202
Forks
6
PR merge metrics
No merged PRs in 30d

Description

```py
class A: ...
A() or 1 # error, we know that it's not a subtype that has an `__eq__`
reveal_type(A()) # Exactly[A]
def f(a: A):
a or 1 # no error
reveal_type(a) # A
```
```py
class A: ...
class B(A): ...
isinstance(A(), B) # error
reveal_type(A()) # Exactly[A]
def f(a: A):
isinstance(a, B) # no error
reveal_type(a) # A
```

Would provide a lot of benefits in terms of 'type tightness'(strict-equality).

Contributor guide

Open the contributing guide

Research direction

Start from the two examples in the issue and trace how basedmypy currently infers concrete class instances and checks `or` and `isinstance` expressions. Establish the intended `Exactly[A]` behavior for direct expressions and parameters, then add coverage for both cases before resolving how it should interact with subtype checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.