ruff/crates/ty_python_semantic/resources/mdtest/assignment
Ibraheem Ahmed 674d3902c6
[ty] Only prefer declared types in non-covariant positions (#22068)
## Summary

The following snippet currently errors because we widen the inferred
type, even though `X` is covariant over `T`. If `T` was contravariant or
invariant, this would be fine, as it would lead to an assignability
error anyways.

```python
class X[T]:
    def __init__(self: X[None]): ...

    def pop(self) -> T:
        raise NotImplementedError

# error: Argument to bound method `__init__` is incorrect: Expected `X[None]`, found `X[int | None]`
x: X[int | None] = X()
```

There are some cases where it is still helpful to prefer covariant
declared types, but this error seems hard to fix otherwise, and makes
our heuristics more consistent overall.
2025-12-19 17:27:31 -05:00
..
annotations.md [ty] Only prefer declared types in non-covariant positions (#22068) 2025-12-19 17:27:31 -05:00
augmented.md [ty] Improve diagnostics for unsupported binary operations and unsupported augmented assignments (#21947) 2025-12-12 21:53:29 +00:00
multi_target.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
unbound.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
walrus.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00