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
{{ message }}
Repository navigation
type[T] constructors don't use TypeVar bounds for parameter inference #2369
When calling a constructor via type[T] where T is bounded, pyrefly should use the bound's __init__ signature to determine valid parameters. Currently it falls through to object.__init__ and accepts any call.
def test[T](cls: type[T]) -> T:
cls(1) # should error: no args for object constructor
return cls()
class A:
def __init__(self, x: int) -> None: pass
def test2[T: A](cls: type[T]) -> T:
a1: A = cls() # should error: missing required arg x
a2: A = cls(1)
return cls()
Note: this unittest is already available in the codebase.
Activity
Handle `type[T]` calls where T is bounded by a class (#2381)