You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ importannotationsfromdataclassesimportdataclassfromfunctoolsimportpartialfromtypingimportAny, TypeVar, ParamSpec, Generic, Protocol, Callable_T=TypeVar("_T")
_P=ParamSpec("_P")
@dataclass(kw_only=True, repr=True)classTask(Generic[_P, _T]):
name: strfunction: Callable[_P, _T]
class_TaskRegistrator(Protocol):
def__call__(self, func: Callable[_P, _T], /, *, name: str= ...) ->Task[_P, _T]:
...
classTaskQueue:
def_register_task(self, func: Callable[_P, _T], *, name: str) ->Task[_P, _T]:
# Actual implementation omittedreturnTask(name=name, function=func)
deftask(self, name: str) ->_TaskRegistrator:
returnpartial(self._register_task, name=name) # E: see below (L29)deftask2(self, name: str) ->Callable[[Callable[_P, _T]], Task[_P, _T]]:
returnpartial(self._register_task, name=name) # E: see below (L32)# And now we see that the problem is even unrelated to `self`:def_register_task(func: Callable[_P, _T], *, name: str) ->Task[_P, _T]:
# Actual implementation omittedreturnTask(name=name, function=func)
deftask(name: str) ->_TaskRegistrator:
returnpartial(_register_task, name=name) # E: see below (L42)
Expected Behavior
From my understanding, no mypy errors should be pointed out. pyright agrees with me (just to test on another typechecker) - all green - but I'm not ready to switch from convenient mypy to pyright (I personally dislike that project for being non-python in python ecosystem, plus my current project relies heavily on Django plugin).
Actual Behavior
Several errors, all located on lines with partial(...) calls.
main.py:29: error: Argument 1 to "partial" has incompatible type "Callable[[Callable[_P, _T], NamedArg(str, 'name')], Task[_P, _T]]"; expected "Callable[..., Task[_P, _T]]" [arg-type]
main.py:32: error: Incompatible return value type (got "partial[Task[_P, _T]]", expected "Callable[[Callable[_P, _T]], Task[_P, _T]]") [return-value]
main.py:32: note: "partial[Task[_P, _T]].__call__" has type "Callable[[VarArg(Any), KwArg(Any)], Task[_P, _T]]"
main.py:32: error: Argument 1 to "partial" has incompatible type "Callable[[Callable[_P, _T], NamedArg(str, 'name')], Task[_P, _T]]"; expected "Callable[..., Task[_P, _T]]" [arg-type]
main.py:42: error: Argument 1 to "partial" has incompatible type "Callable[[Callable[_P, _T], NamedArg(str, 'name')], Task[_P, _T]]"; expected "Callable[..., Task[_P, _T]]" [arg-type]
Found 4 errors in 1 file (checked 1 source file)
Your Environment
Mypy version used: 1.2.0, then master and all versions since 0.990.
Mypy command-line flags: none (with and without --strict result is the same)
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10
The text was updated successfully, but these errors were encountered:
Bug Report
When type checking the code below
mypy
produces a bunch of weird errors, most interesting one beingI'm not sure, but isn't
Callable[[Something], Task[_P, _T]]
always compatible withCallable[..., Task[_P, _T]]
?To Reproduce
You can also see this in playground.
Expected Behavior
From my understanding, no
mypy
errors should be pointed out.pyright
agrees with me (just to test on another typechecker) - all green - but I'm not ready to switch from convenientmypy
topyright
(I personally dislike that project for being non-python in python ecosystem, plus my current project relies heavily on Django plugin).Actual Behavior
Several errors, all located on lines with
partial(...)
calls.Your Environment
--strict
result is the same)mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: