-
Notifications
You must be signed in to change notification settings - Fork 282
Open
Labels
Description
Describe the Bug
The following code should fully type check (unittest can be found in pyrefly/pyrefly/lib/test/callable.rs)
from typing import Callable, ParamSpec, TypeVar, Self, assert_type, overload, Generic
P = ParamSpec("P")
R = TypeVar("R")
T = TypeVar("T")
def accepts_callable(cb: Callable[P, R]) -> Callable[P, R]:
return cb
class Class3:
def __new__(cls, *args, **kwargs) -> Self: ...
def __init__(self, x: int) -> None: ...
r3 = accepts_callable(Class3)
class Class7(Generic[T]):
@overload
def __init__(self: "Class7[int]", x: int) -> None: ...
@overload
def __init__(self: "Class7[str]", x: str) -> None: ...
def __init__(self, x: int | str) -> None:
pass
r7 = accepts_callable(Class7)
# pyrefly incorrectly errors on these - should be OK
assert_type(r7(""), Class7[str]) # E: assert_type(Class7[int], Class7[str]) failed
class Class8(Generic[T]):
def __new__(cls, x: list[T], y: list[T]) -> Self:
return super().__new__(cls)
r8 = accepts_callable(Class8)
# pyrefly incorrectly errors on this - should be OK
assert_type(r8([""], [""]), Class8[str]) # E: assert_type(Class8[Any], Class8[str]) failed
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Reactions are currently unavailable