[ty] Treat declared dataclass fields as instance attributes in own_instance_member#22965
[ty] Treat declared dataclass fields as instance attributes in own_instance_member#22965charliermarsh merged 6 commits intomainfrom
own_instance_member#22965Conversation
Typing conformance resultsNo changes detected ✅ |
|
fc6bc07 to
0c18616
Compare
own_instance_member
crates/ty_python_semantic/resources/mdtest/dataclasses/fields.md
Outdated
Show resolved
Hide resolved
| return None; | ||
| } | ||
|
|
||
| let fields = self.own_fields(db, None, field_policy); |
There was a problem hiding this comment.
The own_fields() call here is probably somewhat expensive, since it isn't a Salsa-tracked method (ClassType::fields() is currently, but not ClassType::own_fields()). This may be the cause of the 2% perf regression on the tanjun benchmark on Codspeed. We could consider adding Salsa caching to that method and see if it gets rid of the regression -- though the regression is small enough that I don't think it should be blocking; we could try adding Salsa caching as a separate, standalone change.
| } | ||
| ) | ||
| .then_some(field.clone()) | ||
| .filter(|field| !field.is_kw_only_sentinel(db)) |
There was a problem hiding this comment.
thsi looks correct, but no tests fail if I make this change
| .filter(|field| !field.is_kw_only_sentinel(db)) |
is it possible to improve the test coverage here?
There was a problem hiding this comment.
(Looking at this.)
bbdb716 to
8ce5ced
Compare
c2259e6 to
36bcc40
Compare
Summary
The PR adds a check in
own_instance_memberto avoid treating dataclass fields with defaults asMember::unbound().I've also fixed cases in which
KW_ONLYattributes are shadowed, as in:We now model the correct constructor (
def __init__(self, _: int, *, name: str) -> None: ...).Closes astral-sh/ty#2636.