Skip to content

Reverted narrowing behavior for discriminating between TypedDicts. Th…#10579

Merged
erictraut merged 1 commit intomainfrom
issue-10517
Jun 10, 2025
Merged

Reverted narrowing behavior for discriminating between TypedDicts. Th…#10579
erictraut merged 1 commit intomainfrom
issue-10517

Conversation

@erictraut
Copy link
Collaborator

…is narrowing behavior isn't technically correct from a type safety standpoint, but until PEP 728 is accepted, it's the only practical way to do this form of discrimination. This addresses #10517.

…is narrowing behavior isn't technically correct from a type safety standpoint, but until PEP 728 is accepted, it's the only practical way to do this form of discrimination. This addresses #10517.
@github-actions
Copy link
Contributor

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

sympy (https://github.com/sympy/sympy)
-   .../projects/sympy/sympy/stats/crv_types.py: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)
-   .../projects/sympy/sympy/stats/crv_types.py: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)
-   .../projects/sympy/sympy/stats/drv.py:268:22 - error: Argument of type "Generator[tuple[Unknown, ...] | Unknown | Sum* | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Sum | int | None, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
+   .../projects/sympy/sympy/stats/drv.py:268:22 - error: Argument of type "Generator[tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | int | None, None, None]" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
-     "Generator[tuple[Unknown, ...] | Unknown | Sum* | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Sum | int | None, None, None]" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
+     "Generator[tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | int | None, None, None]" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
-       Type parameter "_T_co@Iterable" is covariant, but "tuple[Unknown, ...] | Unknown | Sum* | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Sum | int | None" is not a subtype of "_SupportsSumNoDefaultT@sum"
+       Type parameter "_T_co@Iterable" is covariant, but "tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | int | None" is not a subtype of "_SupportsSumNoDefaultT@sum"
-         Type "tuple[Unknown, ...] | Unknown | Sum* | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Sum | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+         Type "tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
-           Type "tuple[Unknown, ...] | Unknown | Sum* | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Sum | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+           Type "tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | int | None" is not assignable to type "_SupportsSumWithNoDefaultGiven"
-   .../projects/sympy/sympy/stats/frv_types.py: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)
-   .../projects/sympy/sympy/stats/rv.py:473:25 - error: Argument of type "Expr | Lambda | Zero | One | Integral | Unknown | Probability | tuple[Unknown, ...] | Sum* | Add | Piecewise | Basic | Sum | Any | NaN | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+   .../projects/sympy/sympy/stats/rv.py: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* | Add | Piecewise | Basic | Sum | Any | NaN | NegativeOne | Integer | ComplexInfinity | Rational | Infinity | NegativeInfinity | Float | Number | int" is not assignable to type "Expr | complex"
+     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"
-   .../projects/sympy/sympy/stats/stochastic_process_types.py:1839:25 - error: Argument of type "tuple[Unknown, ...] | Unknown | Sum* | Expr | Add | Piecewise | Basic | Sum | Any | Zero | NaN | Integral | int | None" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
+   .../projects/sympy/sympy/stats/stochastic_process_types.py:1839:25 - error: Argument of type "tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | Integral | Any | int | None" cannot be assigned to parameter "args" of type "Expr | complex" in function "__new__"
-     Type "tuple[Unknown, ...] | Unknown | Sum* | Expr | Add | Piecewise | Basic | Sum | Any | Zero | NaN | Integral | int | None" is not assignable to type "Expr | complex"
+     Type "tuple[Unknown, ...] | Unknown | Sum | Expr | Zero | NaN | Piecewise | Basic | Integral | Any | int | None" is not assignable to type "Expr | complex"
-     Return type mismatch: base method returns type "Self@Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | Self@Expectation | Literal[0] | None"
+     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"
-       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | Expectation* | Literal[0] | None" is not assignable to type "Basic"
+       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | Expectation* | Literal[0] | None" is not assignable to type "Basic"
-   .../projects/sympy/sympy/stats/symbolic_probability.py: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 | tuple[Unknown, ...] | Sum* | Expr | Add | NaN | Piecewise | Basic | Sum | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0] | None"
-       Type "Unknown | Any | BernoulliDistribution | Probability | Zero | One | tuple[Unknown, ...] | Sum* | Expr | Add | NaN | Piecewise | Basic | Sum | ComplexInfinity | Float | Infinity | Integer | Lambda | Mul | NegativeInfinity | NegativeOne | Number | Rational | Integral | Literal[0] | None" is not assignable to type "Basic"
-         "Literal[0]" is not assignable to "Basic" (reportIncompatibleMethodOverride)
-     Return type mismatch: base method returns type "Basic", override returns type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | Self@Expectation | Literal[0] | None"
+     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"
-       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | Expectation* | Literal[0] | None" is not assignable to type "Basic"
+       Type "Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum | Zero | NaN | Piecewise | Integral | Any | Literal[0] | None" is not assignable to type "Basic"
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:366:12 - error: Operator "-" not supported for types "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | ExpectationMatrix | Literal[0] | None" and "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | ExpectationMatrix | Literal[0] | None"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py: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"
-   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py:414:21 - error: Argument of type "RandomSymbol | Basic | Expectation | Expr | tuple[Unknown, ...] | Unknown | Sum* | Add | Piecewise | Sum | Any | Zero | NaN | Integral | ExpectationMatrix | Literal[0] | None" cannot be assigned to parameter "expr" of type "Basic" in function "simplify"
+   .../projects/sympy/sympy/stats/tests/test_continuous_rv.py: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"

... (truncated 1652 lines) ...

strawberry (https://github.com/strawberry-graphql/strawberry)
-   .../projects/strawberry/strawberry/channels/testing.py:153:54 - error: Argument of type "Any | list[GraphQLFormattedError] | object | Unknown" cannot be assigned to parameter "errors" of type "list[GraphQLFormattedError]" in function "process_errors"
+   .../projects/strawberry/strawberry/channels/testing.py:153:54 - error: Argument of type "list[GraphQLFormattedError] | object | Unknown" cannot be assigned to parameter "errors" of type "list[GraphQLFormattedError]" in function "process_errors"
-     Type "Any | list[GraphQLFormattedError] | object | Unknown" is not assignable to type "list[GraphQLFormattedError]"
+     Type "list[GraphQLFormattedError] | object | Unknown" is not assignable to type "list[GraphQLFormattedError]"

@erictraut erictraut merged commit c165c3f into main Jun 10, 2025
17 checks passed
@erictraut erictraut deleted the issue-10517 branch June 10, 2025 02:17
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