When using @dataclass annotation for a class, pyright refuses the creation of private fields (name starting with _).
I can't find anything explaining why it is a bad practice so I am wondering what is the reason behind it.
Here is a small piece of code to reproduce the message :
from dataclasses import dataclass, field
@dataclass
class Test:
_my_field = field(default=0, init=False)
The exact message is the following :
error: Data field name cannot start with _
Also is there a way to disable this specific rule in pyright ?
I am using pyright 1.0.38 (both extension and command line).
Thanks for reporting this. It's a bug. I misinterpreted the Python spec for dataclass when I implemented this support. I'll remove this check in the next version of pyright.
This is now fixed in 1.0.39, which I just published.
Most helpful comment
This is now fixed in 1.0.39, which I just published.