Summary
Python @dataclass classes can define field metadata via field(default=..., metadata={...}), and code can introspect fields via dataclasses.fields(MyClass). While SymbolExtractor detects class attributes via annotation/assignment (lines 184-282 of SymbolExtractor.Python.cs), it does not model field() calls as distinct symbols, nor does it capture references to field metadata keys. Dataclass field introspection is also not registered as a reference to the dataclass itself (unlike the regex on line 102 for dataclasses.fields()). Field-level type constraints in Callable and Protocol parameterized fields are invisible.
Where
src/CodeIndex/Indexer/Symbols/SymbolExtractor.Python.cs:184-282 — ExtractPythonClassAttributeSymbols processes annotated/assigned attributes but does not distinguish field() construction
src/CodeIndex/Indexer/References/Languages/PythonReferenceExtractor.cs:102-104 — DataclassesFieldsTargetRegex exists but only matches dataclasses.fields() call sites, not the field() definitions themselves
Suggested approach
- Add regex to detect
field(...) calls in class body, extracting the field name and metadata dict keys
- Register each field() metadata key as a symbol or annotation reference
- Extend reference extraction to cover field default factories (e.g.,
field(default_factory=list) → extract list as a reference)
Summary
Python
@dataclassclasses can define field metadata viafield(default=..., metadata={...}), and code can introspect fields viadataclasses.fields(MyClass). While SymbolExtractor detects class attributes via annotation/assignment (lines 184-282 of SymbolExtractor.Python.cs), it does not modelfield()calls as distinct symbols, nor does it capture references to field metadata keys. Dataclass field introspection is also not registered as a reference to the dataclass itself (unlike the regex on line 102 fordataclasses.fields()). Field-level type constraints in Callable and Protocol parameterized fields are invisible.Where
src/CodeIndex/Indexer/Symbols/SymbolExtractor.Python.cs:184-282— ExtractPythonClassAttributeSymbols processes annotated/assigned attributes but does not distinguishfield()constructionsrc/CodeIndex/Indexer/References/Languages/PythonReferenceExtractor.cs:102-104— DataclassesFieldsTargetRegex exists but only matchesdataclasses.fields()call sites, not the field() definitions themselvesSuggested approach
field(...)calls in class body, extracting the field name and metadata dict keysfield(default_factory=list)→ extractlistas a reference)