Skip to content

Mistaken 'Name already defined' for decorated function #4117

Closed
@Zac-HD

Description

@Zac-HD

While working on HypothesisWorks/hypothesis#858, I've found that decorated functions are mis-detected as already defined in another branch, if either both functions or only the second are decorated. I've simplified this to the following example:

def decor(func):
    return func

if True: # or False, or any other condition
    def f(arg):
        yield
else:
    @decor  # not detected as duplicate if this decorator is removed
    def f(arg):
        yield
$ python -m mypy example.py
a.py:8: error: Name 'f' already defined

This bug is still present as of mypy 0.610

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions