mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-09 19:49:43 +00:00
[ty] Improve literal promotion heuristics (#21439)
## Summary Extends literal promotion to apply to any generic method, as opposed to only generic class constructors. This PR also improves our literal promotion heuristics to only promote literals in non-covariant position in the return type, and avoid promotion if the literal is present in non-covariant position in any argument type. Resolves https://github.com/astral-sh/ty/issues/1357.
This commit is contained in:
parent
3e7e91724c
commit
c5d654bce8
13 changed files with 570 additions and 255 deletions
|
|
@ -978,10 +978,10 @@ reveal_type(ParentDataclass.__init__)
|
|||
reveal_type(ChildOfParentDataclass.__init__)
|
||||
|
||||
result_int = uses_dataclass(42)
|
||||
reveal_type(result_int) # revealed: ChildOfParentDataclass[Literal[42]]
|
||||
reveal_type(result_int) # revealed: ChildOfParentDataclass[int]
|
||||
|
||||
result_str = uses_dataclass("hello")
|
||||
reveal_type(result_str) # revealed: ChildOfParentDataclass[Literal["hello"]]
|
||||
reveal_type(result_str) # revealed: ChildOfParentDataclass[str]
|
||||
```
|
||||
|
||||
## Descriptor-typed fields
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue