Repository navigation
fix(dataClasses): recognize KW_ONLY separator for any variable name - #11486
Merged
Rich Chiodo (rchiodo) merged 1 commit intoJun 18, 2026
Merged
Rich Chiodo (rchiodo) merged 1 commit into
Rich Chiodo (rchiodo) merged 1 commit into
Conversation
Python docs state the variable name is ignored for KW_ONLY separators — the convention to use `_` is just that, a convention. Pyright previously required the name to be exactly `_`, causing false positives when alternative names (e.g. `__`) were used.
Rich Chiodo (rchiodo)
approved these changes
Jun 12, 2026
Rich Chiodo (rchiodo)
left a comment
Collaborator
There was a problem hiding this comment.
Approved via Review Center.
Collaborator
|
Looks good — correct, well-scoped fix that aligns with the documented behavior that the KW_ONLY separator name is ignored, with appropriate regression coverage. Approving. |
Rich Chiodo (rchiodo)
approved these changes
Jun 18, 2026
Rich Chiodo (rchiodo)
left a comment
Collaborator
There was a problem hiding this comment.
Approved via Review Center.
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: sympy (https://github.com/sympy/sympy)
- .../projects/sympy/sympy/solvers/tests/test_solvers.py:1216:18 - error: Operator "+" not supported for types "Basic" and "Expr" (reportOperatorIssue)
- .../projects/sympy/sympy/solvers/tests/test_solveset.py:445:30 - error: Cannot access attribute "limit_denominator" for class "NaN"
- Attribute "limit_denominator" is unknown (reportAttributeAccessIssue)
- .../projects/sympy/sympy/solvers/tests/test_solveset.py:445:30 - error: Cannot access attribute "limit_denominator" for class "ComplexInfinity"
- Attribute "limit_denominator" is unknown (reportAttributeAccessIssue)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:315:25 - error: "Set" is not iterable
+ "__iter__" method not defined (reportGeneralTypeIssues)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:315:25 - error: "ConditionSet" is not iterable
+ "__iter__" method not defined (reportGeneralTypeIssues)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2030:20 - error: "__getitem__" method not defined on type "Basic" (reportIndexIssue)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2042:20 - error: "__getitem__" method not defined on type "Basic" (reportIndexIssue)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2055:20 - error: "__getitem__" method not defined on type "Basic" (reportIndexIssue)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2076:16 - error: Argument of type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" is not assignable to type "Sized"
+ "Set" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2077:20 - error: "__getitem__" method not defined on type "Basic" (reportIndexIssue)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2270:16 - error: Argument of type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" is not assignable to type "Sized"
+ "Set" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2351:16 - error: Argument of type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" is not assignable to type "Sized"
+ "Set" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2364:16 - error: Argument of type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" is not assignable to type "Sized"
+ "Set" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2370:16 - error: Argument of type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" is not assignable to type "Sized"
+ "Set" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2538:16 - error: Argument of type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | FiniteSet | Set | Intersection | Union | Complement | Any | ConditionSet" is not assignable to type "Sized"
+ "Set" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
+ .../projects/sympy/sympy/solvers/tests/test_solveset.py:2541:20 - error: Argument of type "Unknown | Basic | Any" cannot be assigned to parameter "obj" of type "Sized" in function "len"
+ Type "Unknown | Basic | Any" is not assignable to type "Sized"
+ "Basic" is incompatible with protocol "Sized"
+ "__len__" is not present (reportArgumentType)
- .../projects/sympy/sympy/stats/joint_rv_types.py:576:27 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "stop" of type "SupportsIndex" in function "__new__"
+ .../projects/sympy/sympy/stats/joint_rv_types.py:576:27 - error: Argument of type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Infinity | NegativeInfinity | Float | Number | Expr" cannot be assigned to parameter "stop" of type "SupportsIndex" in function "__new__"
- Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "SupportsIndex"
+ Type "One | NegativeOne | Zero | Integer | NaN | ComplexInfinity | Rational | Unknown | Infinity | NegativeInfinity | Float | Number | Expr" is not assignable to type "SupportsIndex"
- .../projects/sympy/sympy/stats/rv_interface.py:451:42 - error: Operator "-" not supported for types "Unknown | Basic | Any" and "Rational | NaN | ComplexInfinity"
+ .../projects/sympy/sympy/stats/rv_interface.py:451:42 - error: Operator "-" not supported for types "Unknown | Basic | Any" and "Rational | Unknown"
- Operator "-" not supported for types "Basic" and "Rational"
- Operator "-" not supported for types "Basic" and "NaN"
- Operator "-" not supported for types "Basic" and "ComplexInfinity" (reportOperatorIssue)
+ Operator "-" not supported for types "Basic" and "Rational" (reportOperatorIssue)
+ .../projects/sympy/sympy/stats/symbolic_probability.py:75:9 - error: Method "doit" overrides class "Basic" in an incompatible manner
+ Return type mismatch: base method returns type "Basic", override returns type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]"
+ Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" is not assignable to type "Basic"
+ "Literal[0]" is not assignable to "Basic" (reportIncompatibleMethodOverride)
+ .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1543:12 - error: No overloads for "simplify" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1543:21 - error: Argument of type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+ Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" is not assignable to type "Basic"
+ "Literal[0]" is not assignable to "Basic" (reportArgumentType)
+ .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1545:12 - error: No overloads for "simplify" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1545:21 - error: Argument of type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+ Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" is not assignable to type "Basic"
+ "Literal[0]" is not assignable to "Basic" (reportArgumentType)
+ .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1550:12 - error: No overloads for "simplify" match the provided arguments (reportCallIssue)
+ .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:1550:21 - error: Argument of type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum | Expr | ZeroMatrix | NaN | Piecewise | Basic | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0]" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
... (truncated 433 lines) ...
|
Rich Chiodo (rchiodo)
added a commit
to rchiodo/pyright
that referenced
this pull request
Jun 29, 2026
CPython raises a TypeError when more than one KW_ONLY separator appears in a single dataclass. Detect this and emit a new dataClassDuplicateKwOnly diagnostic on the second separator. Adds DC5 (non-_ separator name) and DC6 (duplicate separator) regression cases and bumps the expected error count. The core KW_ONLY name-guard removal landed separately in microsoft#11486, so this is rebased on top of it. Co-authored-by: Copilot <[email protected]>
Rich Chiodo (rchiodo)
added a commit
that referenced
this pull request
Jun 29, 2026
CPython raises a TypeError when more than one KW_ONLY separator appears in a single dataclass. Detect this and emit a new dataClassDuplicateKwOnly diagnostic on the second separator. Adds DC5 (non-_ separator name) and DC6 (duplicate separator) regression cases and bumps the expected error count. The core KW_ONLY name-guard removal landed separately in #11486, so this is rebased on top of it. Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11451
dataclasses.KW_ONLYmarks a separator field: every parameter declared after it in the class body becomes keyword-only. The Python docs explicitly state that the variable name is ignored —_is merely a convention, and any identifier works equally well at runtime.Before this change, Pyright checked for
=== '_'before evaluating the annotation type, so non-_names like__orkw_sepwere treated as ordinary fields instead of separators. This caused two classes of false-positive diagnostics:reportGeneralTypeIssues— "Fields without default values cannot appear after fields with default values" — when aKW_ONLYseparator with no default appeared after a field that did have one.Fix: Remove the
=== '_'guard so anyTypeAnnotationwhose RHS resolves toKW_ONLYis treated as a separator.A new test sample (
dataclassKwOnly2.py) exercises the three common patterns:__: KW_ONLY,__: KW_ONLYafter a field with a default, and an arbitrary name (kw_sep: KW_ONLY).