Skip to content

Added special-case logic to detect when a class-like symbol created b…#10562

Merged
erictraut merged 1 commit intomainfrom
issue-10550-2
Jun 8, 2025
Merged

Added special-case logic to detect when a class-like symbol created b…#10562
erictraut merged 1 commit intomainfrom
issue-10550-2

Conversation

@erictraut
Copy link
Collaborator

…y calling NewType is used as an actual class for assignability or member accesses. This addresses #10550.

…y calling NewType is used as an actual class for assignability or member accesses. This addresses #10550.
@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2025

Diff from mypy_primer, showing the effect of this PR on open source code:

sympy (https://github.com/sympy/sympy)
-   ...:540:50 - error: "Set" is not iterable
-     "__iter__" method not defined (reportGeneralTypeIssues)
+   ...:2542:9 - error: Method "_cdf" overrides class "SingleContinuousDistribution" in an incompatible manner
+     Return type mismatch: base method returns type "None", override returns type "ComplexInfinity | NaN | Rational | Unknown"
+       Type "ComplexInfinity | NaN | Rational | Unknown" is not assignable to type "None"
+         "ComplexInfinity" is not assignable to "None" (reportIncompatibleMethodOverride)
+   ...:2721:9 - error: Method "_cdf" overrides class "SingleContinuousDistribution" in an incompatible manner
+     Return type mismatch: base method returns type "None", override returns type "Expr | NaN | ComplexInfinity | Rational | Unknown"
+       Type "Expr | NaN | ComplexInfinity | Rational | Unknown" is not assignable to type "None"
+         "Expr" is not assignable to "None" (reportIncompatibleMethodOverride)
-   ...:261:48 - error: Cannot access attribute "doit" for class "tuple[Unknown, ...]"
-     Attribute "doit" is unknown (reportAttributeAccessIssue)
-   ...:261:48 - error: "doit" is not a known attribute of "None" (reportOptionalMemberAccess)
-   ...:268:22 - error: Argument of type "Generator[tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | int | None, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
+   ...:268:22 - error: Argument of type "Generator[Unknown | int | None, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
-     "Generator[tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | int | None, None, None]" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
+     "Generator[Unknown | int | None, None, None]" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
-       Type parameter "_T_co@Iterable" is covariant, but "tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | int | None" is not a subtype of "_SupportsSumNoDefaultT@sum"
+       Type parameter "_T_co@Iterable" is covariant, but "Unknown | int | None" is not a subtype of "_SupportsSumNoDefaultT@sum"
-         Type "tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+         Type "Unknown | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
-           Type "tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+           Type "Unknown | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
-             "Basic" is incompatible with protocol "_SupportsSumWithNoDefaultGiven" (reportArgumentType)
+             "None" is incompatible with protocol "_SupportsSumWithNoDefaultGiven" (reportArgumentType)
+   ...:138:17 - error: Argument of type "NaN | ComplexInfinity | Rational | Unknown | Expr" cannot be assigned to parameter "value" of type "int" in function "__setitem__"
+     Type "NaN | ComplexInfinity | Rational | Unknown | Expr" is not assignable to type "int"
+       "Expr" is not assignable to "int" (reportArgumentType)
-   ...:473:25 - error: Argument of type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
-     Type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum | NaN | Piecewise | Basic | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" is not assignable to type "Expr | complex"
-       Type "Basic" is not assignable to type "Expr | complex"
-         "Basic" is not assignable to "Expr"
-         "Basic" is not assignable to "complex" (reportArgumentType)
-   ...:741:20 - error: "Set" is not iterable
-     "__iter__" method not defined (reportGeneralTypeIssues)
-   ...:1839:25 - error: Argument of type "tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | Integral | Any | int | None" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+   ...:1839:25 - error: Argument of type "tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Integral | int | None" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
-     Type "tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Basic | Integral | Any | int | None" is not assignable to type "Expr | complex"
+     Type "tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Integral | int | None" is not assignable to type "Expr | complex"
-   ...:1894:27 - error: Cannot access attribute "doit" for class "tuple[Unknown, ...]"
-     Attribute "doit" is unknown (reportAttributeAccessIssue)
-     Return type mismatch: base method returns type "Self@Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | Self@Expectation | Literal[0] | None"
+     Return type mismatch: base method returns type "Self@Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | Self@Expectation | Literal[0] | None"
-       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | Expectation* | Literal[0] | None" is not assignable to type "Basic"
+       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | Expectation* | Literal[0] | None" is not assignable to type "Basic"
+   ...:74: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 | ComplexInfinity | Expr | Float | Infinity | Integer | Lambda | NaN | NegativeInfinity | NegativeOne | Number | Piecewise | Rational | Integral | Literal[0]"
+       Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | ComplexInfinity | Expr | Float | Infinity | Integer | Lambda | NaN | NegativeInfinity | NegativeOne | Number | Piecewise | Rational | Integral | Literal[0]" is not assignable to type "Basic"
+         "Literal[0]" is not assignable to "Basic" (reportIncompatibleMethodOverride)
-   ...:123:27 - error: Cannot access attribute "doit" for class "tuple[Unknown, ...]"
-     Attribute "doit" is unknown (reportAttributeAccessIssue)
-     Return type mismatch: base method returns type "Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | Literal[0] | None"
+     Return type mismatch: base method returns type "Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | Literal[0] | None"
-       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | Literal[0] | None" is not assignable to type "Basic"
+       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | Literal[0] | None" is not assignable to type "Basic"
-   ...:41:21 - error: Cannot access attribute "simplify" for class "tuple[Unknown, ...]"
-     Attribute "simplify" is unknown (reportAttributeAccessIssue)
-   ...:41:21 - error: "simplify" is not a known attribute of "None" (reportOptionalMemberAccess)
-   ...:366:12 - error: Operator "-" not supported for types "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0] | None" and "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0] | None"
+   ...:366:12 - error: Operator "-" not supported for types "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | ExpectationMatrix | Literal[0] | None" and "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | ExpectationMatrix | Literal[0] | None"
-   ...:414:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0] | None" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+   ...:414:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | ExpectationMatrix | Literal[0] | None" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
-     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | ExpectationMatrix | Literal[0] | None" is not assignable to type "Basic"
+     Type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Any | Add | Zero | NaN | Piecewise | Integral | ExpectationMatrix | Literal[0] | None" is not assignable to type "Basic"

... (truncated 1925 lines) ...

strawberry (https://github.com/strawberry-graphql/strawberry)
+   ...:153:49 - error: Variable not allowed in type expression (reportInvalidTypeForm)
+   ...:154:15 - error: Variable not allowed in type expression (reportInvalidTypeForm)
-   ...:158:40 - error: Cannot access attribute "pop" for class "_Any"
-     Attribute "pop" is unknown (reportAttributeAccessIssue)
-   ...:171:21 - error: "__setitem__" method not defined on type "_Any" (reportIndexIssue)
-   ...:174:50 - error: Argument expression after ** must be a mapping with a "str" key type (reportCallIssue)
+ ...
+   ...:5:17 - error: Argument of type "type[Upload]" cannot be assigned to parameter "cls" of type "_T@scalar" in function "scalar"
+     Type "FunctionType" is not assignable to type "type"
+       "FunctionType" is not assignable to "type" (reportArgumentType)
+   ...:18:5 - error: Argument of type "type[JSON]" cannot be assigned to parameter "cls" of type "_T@scalar" in function "scalar"
+     Type "FunctionType" is not assignable to type "type"
+       "FunctionType" is not assignable to "type" (reportArgumentType)
+   ...:32:5 - error: Argument of type "type[Base16]" cannot be assigned to parameter "cls" of type "_T@scalar" in function "scalar"
+     Type "FunctionType" is not assignable to type "type"
+       "FunctionType" is not assignable to "type" (reportArgumentType)
+   ...:40:5 - error: Argument of type "type[Base32]" cannot be assigned to parameter "cls" of type "_T@scalar" in function "scalar"
+     Type "FunctionType" is not assignable to type "type"
+       "FunctionType" is not assignable to "type" (reportArgumentType)
+   ...:50:5 - error: Argument of type "type[Base64]" cannot be assigned to parameter "cls" of type "_T@scalar" in function "scalar"
+     Type "FunctionType" is not assignable to type "type"
+       "FunctionType" is not assignable to "type" (reportArgumentType)
+ ...
+   ...:808:37 - error: Argument of type "type[ID]" cannot be assigned to parameter "scalar" of type "type" in function "from_scalar"
+     "FunctionType" is not assignable to "type" (reportArgumentType)
- 378 errors, 69 warnings, 0 informations 
+ 383 errors, 69 warnings, 0 informations 

@erictraut erictraut merged commit 332c215 into main Jun 8, 2025
17 checks passed
@erictraut erictraut deleted the issue-10550-2 branch June 8, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant