ruff/crates/ty_python_semantic/resources/mdtest/dataclasses
Ibraheem Ahmed 1ade4f2081
[ty] Avoid unnecessarily widening generic specializations (#20875)
## Summary

Ignore the type context when specializing a generic call if it leads to
an unnecessarily wide return type. For example, [the example mentioned
here](https://github.com/astral-sh/ruff/pull/20796#issuecomment-3403319536)
works as expected after this change:
```py
def id[T](x: T) -> T:
    return x

def _(i: int):
    x: int | None = id(i)
    y: int | None = i
    reveal_type(x)  # revealed: int
    reveal_type(y)  # revealed: int
```

I also added extended our usage of `filter_disjoint_elements` to tuple
and typed-dict inference, which resolves
https://github.com/astral-sh/ty/issues/1266.
2025-10-16 19:17:37 +00:00
..
dataclass_transform.md [ty] Support dataclass-transform field_specifiers (#20888) 2025-10-16 20:49:11 +02:00
dataclasses.md [ty] Do not assume that fields have a default value (#20914) 2025-10-16 12:49:24 +02:00
fields.md [ty] Avoid unnecessarily widening generic specializations (#20875) 2025-10-16 19:17:37 +00:00