-
Notifications
You must be signed in to change notification settings - Fork 273
Open
Description
Describe the Bug
The following example type checks fine with mypy/pyright, but raises
ERROR `MySeries` is not assignable to upper bound `NativeSeries` of type variable `T` [bad-specialization]
--> t.py:15:17
|
15 | def to_foo() -> Foo[MySeries]:
| ^^^^^^^^^^^^^
|
`MySeries.filter` has type `BoundMethod[MySeries, (self: MySeries, _predicate: Iterable[bool]) -> MySeries]`, which is not assignable to `BoundMethod[MySeries, (self: MySeries, *args: Any, **kwargs: Any) -> Any]`, the type of `NativeSeries.filter`for pyrefly
from typing import Generic, Sized, Iterable, Any, TypeVar, Protocol, Self
class NativeSeries(Protocol):
def filter(self, *args: Any, **kwargs: Any) -> Any: ...
class MySeries:
def filter(self, _predicate: Iterable[bool]) -> Self:
return self
T = TypeVar('T', bound=NativeSeries)
class Foo(Generic[T]):
...
def to_foo() -> Foo[MySeries]:
...spotted in narwhals
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels