mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-05 16:10:36 +00:00
![]() ## Summary Part of astral-sh/ty#994. The goal of this PR was to add correct behavior for attribute access on the top and bottom materializations. This is necessary for the end goal of using the top materialization for narrowing generics (`isinstance(x, list)`): we want methods like `x.append` to work correctly in that case. It turned out to be convenient to represent materialization as a TypeMapping, so it can be stashed in the `type_mappings` list of a function object. This also allowed me to remove most concrete `materialize` methods, since they usually just delegate to the subparts of the type, the same as other type mappings. That is why the net effect of this PR is to remove a few hundred lines. ## Test Plan I added a few more tests. Much of this PR is refactoring and covered by existing tests. ## Followups Assigning to attributes of top materializations is not yet covered. This seems less important so I'd like to defer it. I noticed that the `materialize` implementation of `Parameters` was wrong; it did the same for the top and bottom materializations. This PR makes the bottom materialization slightly more reasonable, but implementing this correctly will require extending the struct. |
||
---|---|---|
.. | ||
resources | ||
src | ||
tests | ||
build.rs | ||
Cargo.toml | ||
mdtest.py | ||
mdtest.py.lock |