KotlinIsland / KotlinIsland/basedmypy

make `allow-redefinition` better / require annotation

Open
#205 1 comment 0 reactions 0 assignees View on GitHub
feature feedback p-2
Dominant language
Python
Stars
202
Forks
6
PR merge metrics
No merged PRs in 30d

Description

```py
a: int | str = 1
reveal_type(a) # int | str
a = ""
reveal_type(a) # str
```
This is actually redefining a as `str`, not reassigning as part of the union.

What if it always needed a type annotation to redefine:
```py
a: int | str = 1
a = str(a) # no redefine
a = 1 # no error, and no redefine 👍
```
should need:
```py
a: int | str = 1
a: str = str(a)
a = 1 # error 👍
```

Using `Infer` would also be usable here no announce a redefinition
```py
a = 1
a: Infer = str(a)
```
Perhaps even a separate annotation `Redefine`

Contributor guide

Open the contributing guide

Research direction

Start by tracing the existing `allow-redefinition` handling in the type checker. Compare the issue's annotation proposals and examples, then clarify which syntax and semantics are intended; done means the chosen rule distinguishes ordinary reassignment from explicit redefinition and has agreed behavior for the shown cases.

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.