You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By running the attached script you can see how attrs actually works with these kind of classes, and by pasting the same code into VSCode - you will see that pylance flags the line b = B(3,4) as if it has an issue
Expected behavior
Pylance shouldn't flag this kind of code
Actual behavior
Pylance shows the following
Argument missing for parameter "z"Pylance[reportGeneralTypeIssues]
Attrs uses dataclass_transform (documented in PEP 681) to describe its behavior to static type checkers. The dataclass_transform decorator indicates that the class (in this case, attrs.define) has the same behaviors and semantics as the stdlib dataclass. For the most part, attrs.define does act consistently with dataclass. However, it is deviating from dataclass in how it treats kw_only in an field override. I don't know if this is intentional or an unintended oversight (i.e. a bug) in attrs. You may want to report it to the maintainers of attrs and see if they're willing to fix it so it's consistent with dataclass.
In any case, to make this work with pylance and other static analysis tools, you will need to modify your code slightly. In particular, you need to repeat the kw_only=True in the override of field x within class B. This modified code works with with both dataclass and attrs.define.
Environment data
Code Snippet
Repro Steps
b = B(3,4)
as if it has an issueExpected behavior
Pylance shouldn't flag this kind of code
Actual behavior
Pylance shows the following
Logs
The text was updated successfully, but these errors were encountered: