[ty] Preserve qualifiers when accessing attributes on unions/intersections (#20114)

## Summary

Properly preserve type qualifiers when accessing attributes on unions
and intersections. This is a prerequisite for
https://github.com/astral-sh/ruff/pull/19579.

Also fix a completely wrong implementation of
`map_with_boundness_and_qualifiers`. It now closely follows
`map_with_boundness` (just above).

## Test Plan

I thought about it, but didn't find any easy way to test this. This only
affected `Type::member`. Things like validation of attribute writes
(where type qualifiers like `ClassVar` and `Final` are important) were
already handling things correctly.
This commit is contained in:
David Peter 2025-08-27 20:01:45 +02:00 committed by GitHub
parent ce1dc21e7e
commit 0b3548755c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 22 deletions

View file

@ -398,7 +398,7 @@ def f_okay(c: Callable[[], None]):
c.__qualname__ = "my_callable"
result = getattr_static(c, "__qualname__")
reveal_type(result) # revealed: Never
reveal_type(result) # revealed: property
if isinstance(result, property) and result.fset:
c.__qualname__ = "my_callable" # okay
```