python / python/mypy

allow_redefinition ignored for functions

Open
#10,765 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report

Mypy complains with error: Name "step_impl" already defined on line 13 error for functions, although allow_redefinition is set to True.

To Reproduce

  1. Add mypy.ini configuration (listed below)
  2. Add behave tests; for example:
@given("I am on the main page")
def step_impl(context):
    pass


@when("I type login and password")
def step_impl(context):
    pass


@then("I am logged in")
def step_impl(context):
    pass
  1. Run mypy

Expected Behavior

Mypy checks pass because allow_redefinition is set to True.

Actual Behavior

Mypy fails with

 error: Name "step_impl" already defined on line 13

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
python_version = 3.6
allow_redefinition = True
ignore_missing_imports = True
check_untyped_defs = False
  • Python version used: 3.6
  • Operating system and version: Ubuntu 20.04.2

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 reported error with the shown mypy.ini configuration and behave-style repeated function definitions. Then trace mypy's handling of function redefinitions and add a regression test; done means allow_redefinition suppresses this diagnostic while unrelated duplicate-definition errors remain reported.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.