Skip to content

Promote literals in contravariant position, not just invariant #3016

@Tinche

Description

@Tinche

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)

Metadata

Metadata

Assignees

Labels

genericsBugs or features relating to ty's generics implementation

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions