mirror of
https://github.com/astral-sh/ruff
synced 2026-01-07 14:44:17 -05:00
## Summary This PR improves the `is_safe_mutable_class` function in `infer.rs` in several ways: - It uses `KnownClass::to_instance()` for all "safe mutable classes". Previously, we were using `SpecialFormType::instance_fallback()` for some variants -- I'm not totally sure why. Switching to `KnownClass::to_instance()` for all "safe mutable classes" fixes a number of TODOs in the `assignment.md` mdtest suite - Rather than eagerly calling `.to_instance(db)` on all "safe mutable classes" every time `is_safe_mutable_class` is called, we now only call it lazily on each element, allowing us to short-circuit more effectively. - I removed the entry entirely for `TypedDict` from the list of "safe mutable classes", as it's not correct. `SpecialFormType::TypedDict.instance_fallback(db)` just returns an instance type representing "any instance of `typing._SpecialForm`", which I don't think was the intent of this code. No tests fail as a result of removing this entry, as we already check separately whether an object is an inhabitant of a `TypedDict` type (and consider that object safe-mutable if so!). ## Test Plan mdtests updated