-
Notifications
You must be signed in to change notification settings - Fork 281
Labels
Milestone
Description
Describe the Bug
When a constrained TypeVar is called with a subtype of a constraint (e.g. AnyStr = TypeVar("AnyStr", str, bytes)) pyrefly resolves to the subtype instead of the constraint. For example, passing MyStr(str) should resolve AnyStr to str, not MyStr.
`from typing import TypeVar, assert_type
AnyStr = TypeVar("AnyStr", str, bytes)
def concat(x: AnyStr, y: AnyStr) -> AnyStr:
return x + y
class MyStr(str): ...
def test(m: MyStr, s: str):
assert_type(concat(m, m), str) # pyrefly says MyStr, should be str
assert_type(concat(m, s), str) # pyrefly says MyStr and also rejects s`
Note: this unittest is already available in the codebase.
Sandbox link:
Reactions are currently unavailable