-
Notifications
You must be signed in to change notification settings - Fork 276
Promote literals in contravariant position, not just invariant #3016
Copy link
Copy link
Closed
astral-sh/ruff
#23888Labels
genericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementation
Milestone
Description
Summary
Howdy!
So I was reviewing a PR to the attrs repo just now. This PR seems to be running into an issue with ty so I wanted to dig deeper.
Not to get bogged down in the weeds of how attrs works, here's a small repro: https://play.ty.dev/ee4a7f0b-5084-4477-834f-406106d62381
So the problem is when you call make_gt_validator(0), the result is Callable[[Literal[0], bool] instead of Callable[[int], bool]. The ty behavior here actually looks correct to me, so I'm very willing to concede the type hints are wrong. But then my issue is how to type this to get the int callable instead. Would love your thoughts on this.
Version
ty 0.0.21 (c1ad9f2 2026-03-06)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
genericsBugs or features relating to ty's generics implementationBugs or features relating to ty's generics implementation