-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type is incompatible with Callable when using Concatenate #14321
Comments
The difference in behavior between if subtypes.is_subtype(dispatched_arg_type, erase_typevars(erase_to_bound(selfarg))):
In the case of if (
right_by_name is not None
and right_by_pos is not None
and right_by_name != right_by_pos
and (right_by_pos.required or right_by_name.required)
and strict_concatenate_check
):
return False
I feel like if from typing import ParamSpec, TypeVar
P = ParamSpec("P")
T = TypeVar("T")
def decorator(f: Callable[Concatenate[str, P], T]) -> Callable[P, T]:
def new_func(*args: P.args, **kwargs: P.kwargs) -> T:
return f("my_special_str", *args, **kwargs)
return new_func
@decorator # OK
def foo(foo_param_1: str) -> None:
... @A5rocks @cdce8p @JukkaL Does my reasoning and proposed change seem sound? What change related to the "Phase 2" condition should be made s.t. the subtype check passes? |
Fixes #15734 Fixes #15188 Fixes #14321 Fixes #13107 (plain Callable was already working, this fixes the protocol example) Fixes #16058 It looks like treating trivial suffixes (especially for erased callables) as "whatever works" is a right thing, because it reflects the whole idea of why we normally check subtyping with respect to an e.g. erased type. As you can see this fixes a bunch of issues. Note it was necessary to make couple more tweaks to make everything work smoothly: * Adjust self-type erasure level in `checker.py` to match other places. * Explicitly allow `Callable` as a `self`/`cls` annotation (actually I am not sure we need to keep this check at all, since we now have good inference for self-types, and we check they are safe either at definition site or at call site).
Bug Report
As expected, a class
A
can be typed asType[A]
orCallable[P, A]
, whereP
is aParamSpec
.Using
Concatenate
then, you should also be able to bindA
toCallable[Concatenate[<type>, P], A]
, where<type>
is the type ofA
's first constructor parameter, but mypy currently errors when you attempt this.To Reproduce
gist: https://gist.github.com/mypy-play/1cab71a52f3d7f3a4e9045e6e68eabe0
mypy-playground: https://mypy-play.net/?mypy=latest&python=3.10&gist=1cab71a52f3d7f3a4e9045e6e68eabe0
Expected Behavior
No error should be raised.
Actual Behavior
Your Environment
The text was updated successfully, but these errors were encountered: