-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrong
Description
Bug Report
overloaded class-decorator is seen as not Callable when used on an overloaded method
(A clear and concise description of what the bug is.)
To Reproduce
from collections.abc import Callable
from typing import Any, Generic, TypeVar, overload
from typing_extensions import ParamSpec, Self, reveal_type
_P = ParamSpec("_P")
_R = TypeVar("_R")
class DecoratorClass(Generic[_P, _R]):
def __new__(cls, func: Callable[_P, _R] | None = None) -> Self: ...
@overload
def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R: ...
@overload
def __call__(self, *args: Any, backend: str, **backend_kwargs: Any) -> _R: ...
@overload
@DecoratorClass
def overload_first(foo: str) -> None: ...
@overload
@DecoratorClass
def overload_first(foo: int) -> None: ...
@DecoratorClass
@overload
def overload_second(foo: str) -> None: ...
@DecoratorClass
@overload
def overload_second(foo: int) -> None: ...
_ = reveal_type(overload_first)
_ = reveal_type(overload_second)
Expected Behavior
In the short term: Maybe a better error message? It is not true that DecoratorClass
is not callable here.
In the long term: overload-expansion ? Is that even feasible?
Actual Behavior
stubs\networkx\networkx\__init__.pyi:15: error: "DecoratorClass[[str], None]" not callable [misc]
stubs\networkx\networkx\__init__.pyi:18: error: "DecoratorClass[[int], None]" not callable [misc]
stubs\networkx\networkx\__init__.pyi:23: error: "DecoratorClass[[str], None]" not callable [misc]
stubs\networkx\networkx\__init__.pyi:26: error: "DecoratorClass[[int], None]" not callable [misc]
stubs\networkx\networkx\__init__.pyi:30: error: Cannot determine type of "overload_first" [has-type]
stubs\networkx\networkx\__init__.pyi:30: note: Revealed type is "Any"
stubs\networkx\networkx\__init__.pyi:31: error: Cannot determine type of "overload_second" [has-type]
stubs\networkx\networkx\__init__.pyi:31: note: Revealed type is "Any"
Your Environment
- Mypy version used: mypy 1.8.0 (compiled: yes)
- Mypy command-line flags:
--platform win32 --python-version 3.8
- Mypy configuration options from
mypy.ini
(and other config files): From typeshed - Python version used: Python 3.9.13
Additional information
For comparison, pyright currently accepts the above and sees the type as such: (only the last method overload is kept, with the class overload)
Running Pyright (base configs) for Python 3.8...
9.6.2
Running: C:\Program Files\nodejs\npx.CMD pyright@1.1.342 stubs/networkx --pythonversion 3.8
e:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\__init__.pyi
e:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\__init__.pyi:30:17 - information: Type of "overload_first" is "DecoratorClass[(foo: int), None]"
e:\Users\Avasam\Documents\Git\typeshed\stubs\networkx\networkx\__init__.pyi:31:17 - information: Type of "overload_second" is "DecoratorClass[(foo: int), None]"
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrong