ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Dataclasses: Detect subclasses trying setting a classvar for an inherited field

Open frenck opened this issue 2 years ago • 3 comments

It would be nice if Ruff was able to detect this case:

image

No linter available detects the case in B, which can lead to unexpected behavior.

../Frenck

frenck avatar Nov 15 '23 07:11 frenck

This seems sensible, but it's worth noting we are currently limited to looking for base classes in the same file so if your base dataclass type is defined somewhere else we will not be able to say if the field exists on it.

zanieb avatar Nov 15 '23 15:11 zanieb

@zanieb, what I understand is that this is a request for a new rule, and what you're saying is that implementing the rule today would be limited by the fact that Ruff doesn't support multi-file analysis. Is my understanding correct?

MichaReiser avatar Mar 21 '24 13:03 MichaReiser

@MichaReiser that sounds right to me.

zanieb avatar Mar 21 '24 15:03 zanieb