python / python/mypy

New semantic analyzer: allow redefinition of star-imported functions if type is the same

Open
#6,950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

false-positive priority-1-normal semantic-analyzer
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Consider this test case:

[case testReExportOtherSameType]
from low_level import *

def func(arg: str) -> int:
    ...

[file low_level.py]
def func(arg: str) -> int:
    ...

It is currently allowed by old analyzer (likely by accident), but prohibited by the new one. Old analyzer still prohibits this if the function is imported by name instead of star import. Although behavior of the new analyzer is more consistent, it may be sometimes useful to allow the redefinition (for example when star import re-exports hundred functions).

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 with the test case testReExportOtherSameType and its two files, which demonstrate a star import from low_level.py followed by a same-signature definition. Read the new semantic analyzer's handling of star-imported functions and compare it with the old analyzer. Done means the intended same-type redefinition behavior is covered by a passing test without changing the separate named-import behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
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.