python / python/mypy

`allow-redefinition` should perform exhaustive branch analysis

Open
#11,967 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

def func(item: int) -> None:
    print(item)
    if True:
        item = "amogus"
    else:
        item = "amogus"     

main.py:3: error: Incompatible types in assignment (expression has type "str", variable has type "int")

In this snipped item is exhaustively redefined to str. I think it would be good if mypy could pick up on that.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with mypy and trace the allow-redefinition handling through the branch-analysis code. Identify how exhaustive if branches are represented and add coverage showing that identical redefinitions in both branches are accepted; done means the example no longer reports the incompatible assignment while non-exhaustive cases retain their checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.