equinox icon indicating copy to clipboard operation
equinox copied to clipboard

Class fields and instance fields behavior

Open ASEM000 opened this issue 1 year ago • 3 comments

Hello, Patrick

currently, data classes allow fields to be either class or instance variables for example

@dc.dataclass
class Test:
    a:int = 1
    def __init__(self) -> None:
        pass


Test().__dict__ # {}
Test.__dict__['a'] # 1 -> class variable

I think it is better to log a warning or to raise an uninitialized field error to disallow this behavior. As the user might be under the impression that a is a parameter of the Test instance (as shown in the Test repr ) while it's not.

ASEM000 avatar Mar 26 '23 09:03 ASEM000