[ty] Make dataclass own_fields a salsa::tracked method by charliermarsh · Pull Request #24620 · astral-sh/ruff (original) (raw)

I think you can avoid a .clone() and some unnecessary double-memoisation for the NamedTuple case by moving the fields() caching to a fields_inner function:

diff --git a/crates/ty_python_semantic/src/types/class/static_literal.rs b/crates/ty_python_semantic/src/types/class/static_literal.rs index 4c33b1dfa1..c7b41a840b 100644 --- a/crates/ty_python_semantic/src/types/class/static_literal.rs +++ b/crates/ty_python_semantic/src/types/class/static_literal.rs @@ -1605,12 +1605,26 @@ impl<'db> StaticClassLiteral<'db> { /// Returns a list of all annotated attributes defined in this class, or any of its superclasses. /// /// See [StaticClassLiteral::own_fields] for more details.

@@ -1621,11 +1635,11 @@ impl<'db> StaticClassLiteral<'db> { DynamicTypedDict(DynamicTypedDictLiteral<'db>), }