-
-
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
regression with Generic/ParamSpec between 1.4.1 and 1.5.0 #15844
Comments
Hmm, this bisects to #15490 |
Here's a repro with much less going on:
where |
For what it's worth, I'm not sure that an |
Heh, this is a fun/annoying corner case. I agree it doesn't make much sense to ever treat I'm actually surprised mypy isn't emitting a class Transformer(Generic[P, T]):
def __init__(self, transform_cls: Callable[P, Transform[P, T]]) -> None:
raise NotImplementedError The complication, however, is that there are other reasons you might want to define >>> from typing import Protocol
>>> class Foo(Protocol):
... x: int
... def __init__(self, x: int) -> None:
... self.x = x * 2
...
>>> class Bar(Foo):
... def __init__(self, x: int, y: int) -> None:
... super().__init__(x)
... self.y = y
...
>>> b = Bar(2, 3)
>>> vars(b)
{'x': 4, 'y': 3} PEP-544 explicitly states that it's okay to call methods defined on protocol classes from instances of nominal subclasses of those protocols. The difference here is that I don't think that necessarily means that you shouldn't be able to define generic from typing import Any, Callable, ParamSpec, TypeVar, Protocol
P = ParamSpec("P")
R = TypeVar("R")
class Interface(Protocol[P, R]):
f: Callable[P, R]
args: tuple[Any, ...]
kwargs: dict[str, Any]
def __init__(self, f: Callable[P, R], *args: P.args, **kwargs: P.kwargs) -> None:
self.f = f
self.args = args
self.kwargs = kwargs
class Concrete(Interface[[int], int]): pass |
You all clearly have a lot more depth in how I grabbed onto |
My 5 cents here (as the author of the PEP): Indeed until recently we didn't check |
Bug Report
With
1.5.0
, some of our software has started to surface avar-annotated
("Need type annotation for") error that it did not surface with1.4.1
; I could not find anything in the 1.5.0 release notes that suggested that this was intentional.To Reproduce
Our actual software is a bit domain-specific, but I've tried to extract the details; the concept involves a data descriptor that attaches a callable to a class and generates a new callable that inverts how the callable's constructor and runtime arguments are supplied. The solution depends on
ParamSpec
to preserve the argument signatures and usesGeneric
so that the same internals can be used for different functions.Expected Behavior
No errors from mypy. This is true for
1.4.1
.Actual Behavior
Errors. This is true for
1.5.0
Your Environment
1.4.1
and1.5.0
mypy.ini
(and other config files): n/aThe text was updated successfully, but these errors were encountered: