python / python/mypy

enigmatic "name already defined" error

Open
#7,206 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-1-normal
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?

Bug.

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

There are four pieces of code:

def func(x: int) -> int:
    return x + 1

def func(x):
    return x
def func(x):
    return x

def func(x: int) -> int:
    return x + 1
from test import func

def func(x: int) -> int:
    return x + 1
def func(x: int) -> int:
    return x + 1

from test import func

Whenever test is used as a module, test.py contains

def func(x):
    return x
  • What is the actual behavior/output?

The first three examples emits "Name 'func' already defined" error, but not the last

  • What is the behavior/output you expect?

All four should emit this error.

  • What are the versions of mypy and Python you are using?

mypy 0.720+dev.dc6da54f50d5443fe46308046719043eba03c84d (master at the time of bug report)
Python 3.7.3

  • What are the mypy flags you are using? (For example --strict-optional)

None.

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 running the four inline reproductions with the reported mypy version, using test.py for the imported function. Compare the diagnostics for each import and redefinition order. Done means the behavior is consistent with the report's expectation that all four cases emit the duplicate-definition error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.