python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.5k stars 2.83k forks source link

`no-redef` issued with package import but not with local import #15170

Open bersbersbers opened 1 year ago

bersbersbers commented 1 year ago

Bug Report

I can type-annotate untyped imports from a local file, but not from a package (in which case I get a no-redef error).

To Reproduce

my_local.py

from funcy.decorators import decorator

@decorator
def retry(call, tries, errors=Exception, timeout=0, filter_errors=None):
    pass

bug.py

from typing import Callable

# Works without error message
r1: Callable
from my_local import retry as r1

# pip install funcy
# Throws a no-redef error
r2: Callable
from funcy.flow import retry as r2

Expected Behavior

Same behavior (no error) in both cases.

Actual Behavior

my_local.py:1: error: Skipping analyzing "funcy.decorators": module is installed, but missing library stubs or py.typed marker  [import]
my_local.py:5: error: Function is missing a type annotation  [no-untyped-def]
bug.py:4: error: Missing type parameters for generic type "Callable"  [type-arg]
bug.py:9: error: Missing type parameters for generic type "Callable"  [type-arg]
bug.py:10: error: Skipping analyzing "funcy.flow": module is installed, but missing library stubs or py.typed marker  [import]
bug.py:10: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
bug.py:10: error: Name "r2" already defined on line 9  [no-redef]
Found 6 errors in 2 files (checked 1 source file)

Your Environment

Somewhat related: https://github.com/python/mypy/issues/13914

bersbersbers commented 1 year ago

Some additional details can be found in https://stackoverflow.com/q/76152464