Pyright: Why does pyright refuse data field names starting with _ ?

Created on 17 Jun 2019  路  2Comments  路  Source: microsoft/pyright

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).

addressed in next version bug

Most helpful comment

This is now fixed in 1.0.39, which I just published.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings