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
Constrained TypeVar resolves to subtype instead of constraint #2370
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.
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Activity
jackulau commentedon Feb 10, 2026
down to look into this!
migeed-z commentedon Feb 10, 2026
thank you so much! assigned :)
Constrained TypeVar resolves to constraint instead of subtype
Constrained TypeVar resolves to constraint instead of subtype
Constrained TypeVar resolves to constraint instead of subtype
Constrained TypeVar resolves to constraint instead of subtype
github-actions commentedon Feb 25, 2026
This issue has someone assigned, but has not had recent activity for more than 2 weeks.
If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.
Thank you for your contributions!
Add github workflow for v1 issue ranking
Add github workflow for v1 issue ranking
migeed-z commentedon Apr 23, 2026
This no longer errors. Closing