ruff
7b7ea737 - [ty] Fix visibility of field specifiers when models are nested inside methods (#23069)

Commit
177 days ago
[ty] Fix visibility of field specifiers when models are nested inside methods (#23069) ## Summary The right hand side of annotated assignments inside methods of a class are treated as standalone expressions. Therefore, if someone defines a dataclass-transformer model inside a method like this … ```py class Outer: def method(self): @create_model class Model: x: int = field(kw_only=True) y: str ``` … we infer the right hand side of `x: int = field(kw_only=True)` as a standalone expression. Previously though, we did not set up the `TypeInferenceBuilder::dataclass_field_specifiers` field in those cases. This meant that `field` was not recognized as a field-specifier function. ## Ecosystem impact ```diff + tests/test_hooks.py:154:48: error[missing-argument] No argument provided for required parameter `y` + tests/test_next_gen.py:142:14: error[unresolved-attribute] Object of type `dataclasses.Field` has no attribute `validator` + tests/test_next_gen.py:380:14: error[unresolved-attribute] Object of type `dataclasses.Field` has no attribute `validator` ``` These are unavoidable, I believe. They would require an `attr`s plugin. We have similar errors elsewhere already. These new diagnostics only appear because we previously thought that those fields had default values (since we didn't recognize the right hand side as a field-specifier call). ## Test Plan Regression test.
Author
Parents
Loading