Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix second generic for AbstractContextManager being ignored when determining whether the context manager can suppress exceptions #963

Merged
merged 1 commit into from
Dec 21, 2024

Conversation

DetachHead
Copy link
Owner

fixes #962

…termining whether the context manager can suppress exceptions
Copy link
Contributor

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

sympy (https://github.com/sympy/sympy)
-     Type of "degree" is "((gen: int = 0) -> NegativeInfinity) | Unknown" (reportUnknownMemberType)
+     Type of "degree" is "((gen: int = 0) -> (NegativeInfinity | Unknown)) | Unknown" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/crv_types.py:2542:9 - warning: Return type, "ComplexInfinity | Rational | NaN | Integer | Half | Unknown", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/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 | Rational | NaN | Integer | Half | Unknown"
+       Type "ComplexInfinity | Rational | NaN | Integer | Half | Unknown" is not assignable to type "None"
+         "ComplexInfinity" is not assignable to "None" (reportIncompatibleMethodOverride)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/crv_types.py:2544:16 - warning: Return type, "ComplexInfinity | Rational | NaN | Integer | Half | Unknown", is partially unknown (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/crv_types.py:2721:9 - warning: Return type, "Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Unknown", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/crv_types.py:2721:9 - warning: Return type, "Expr | Unknown | NaN | One | NegativeOne | Zero | Integer | Rational | ComplexInfinity | Half", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/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 | Unknown | NaN | One | NegativeOne | Zero | Integer | Rational | ComplexInfinity | Half"
+       Type "Expr | Unknown | NaN | One | NegativeOne | Zero | Integer | Rational | ComplexInfinity | Half" is not assignable to type "None"
+         "Expr" is not assignable to "None" (reportIncompatibleMethodOverride)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/crv_types.py:2723:16 - warning: Return type, "Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Unknown", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/crv_types.py:2723:16 - warning: Return type, "Expr | Unknown | NaN | One | NegativeOne | Zero | Integer | Rational | ComplexInfinity | Half", is partially unknown (reportUnknownVariableType)
-     Type of "summation" is "(f: Unknown, ...) -> (tuple[Unknown, ...] | Unknown | Self@Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None)" (reportUnknownVariableType)
+     Type of "summation" is "(f: Unknown, ...) -> (tuple[Unknown, ...] | Unknown | Self@Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | Sum | None)" (reportUnknownVariableType)
-     Type of "cdf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
+     Type of "cdf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
-     Type of "cf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
+     Type of "cf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
-     Type of "mgf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
+     Type of "mgf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
-     Type of "cdf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
+     Type of "cdf" is "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:150:9 - warning: Return type, "Unknown | tuple[Unknown, ...] | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | Literal[0] | None", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:150:9 - warning: Return type, "Unknown | tuple[Unknown, ...] | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | Literal[0] | None", is partially unknown (reportUnknownParameterType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:170:24 - warning: Return type, "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:170:24 - warning: Return type, "tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None", is partially unknown (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:228:9 - warning: Return type, "Zero | One | Probability | Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | NaN | Piecewise | Basic | Equality | int | NegativeOne | Integer | Rational | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:228:9 - warning: Return type, "Zero | One | Probability | Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | NaN | Piecewise | Basic | Equality | int | NegativeOne | Integer | Rational | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number", is partially unknown (reportUnknownParameterType)
-     Type of "prob" is "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | int | None" (reportUnknownVariableType)
+     Type of "prob" is "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | int | None" (reportUnknownVariableType)
-     Type of "eval_prob" is "(_domain: Unknown) -> (Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | int | None)" (reportUnknownMemberType)
+     Type of "eval_prob" is "(_domain: Unknown) -> (Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | int | None)" (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:251:16 - warning: Return type, "Probability | Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | int | One | NegativeOne | Integer | Rational | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:251:16 - warning: Return type, "Probability | Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | int | One | NegativeOne | Integer | Rational | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | Number", is partially unknown (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:253:9 - warning: Return type, "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | int | None", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:253:9 - warning: Return type, "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | int | None", is partially unknown (reportUnknownParameterType)
-     Type of "rv" is "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
+     Type of "rv" is "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None" (reportUnknownVariableType)
-     Type of "doit" is "Unknown | ((**hints: Unknown) -> (tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Add | Zero | NaN | Piecewise | Basic | None)) | ((**hints: Unknown) -> Self@Expr) | ((**hints: Unknown) -> Expr) | Any | ((**hints: Unknown) -> Add) | ((**hints: Unknown) -> Zero) | ((**hints: Unknown) -> NaN) | ((**hints: Unknown) -> Piecewise) | ((**hints: Unknown) -> Basic) | ((**hints: Unknown) -> Equality)" (reportUnknownMemberType)
+     Type of "doit" is "Unknown | ((**hints: Unknown) -> (tuple[Unknown, ...] | Unknown | Sum | Self@Expr | Expr | Any | Zero | NaN | Piecewise | Basic | Equality | None)) | ((**hints: Unknown) -> Self@Expr) | ((**hints: Unknown) -> Expr) | Any | ((**hints: Unknown) -> Zero) | ((**hints: Unknown) -> NaN) | ((**hints: Unknown) -> Piecewise) | ((**hints: Unknown) -> Basic) | ((**hints: Unknown) -> Equality)" (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/sympy/sympy/stats/drv.py:262:20 - warning: Return type, "Self@Expr | tuple[Unknown, ...] | Unknown | Sum | Expr | Any | Add | Zero | NaN | Piecewise | Basic | Equality | None", is partially unknown (reportUnknownVariableType)

... (truncated 2410 lines) ...

scikit-learn (https://github.com/scikit-learn/scikit-learn)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:994:5 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:994:52 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:996:12 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:995:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:999:70 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1001:12 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1000:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1004:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1005:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1005:35 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1007:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1006:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1010:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1011:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1011:66 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1013:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1012:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1016:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1017:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1017:60 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1019:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1018:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1022:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1025:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1025:50 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1027:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1026:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1030:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1031:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1031:81 - warning: Type of "cm" is unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1033:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1032:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1036:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1037:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1037:35 - warning: Type of "cm" is unknown (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1038:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1039:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1043:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1042:61 - warning: Type of "cm" is unknown (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1048:9 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1044:16 - warning: Type of "raised_and_matched" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1050:9 - warning: Code is unreachable (reportUnreachable)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1052:9 - warning: Code is unreachable (reportUnreachable)
-   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1053:13 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/scikit-learn/sklearn/utils/tests/test_testing.py:1051:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
- 16998 errors, 198072 warnings, 0 notes
+ 16998 errors, 198077 warnings, 0 notes

spack (https://github.com/spack/spack)
-   /tmp/mypy_primer/projects/spack/lib/spack/spack/test/llnl/util/lang.py:294:5 - warning: Code is unreachable (reportUnreachable)
-   /tmp/mypy_primer/projects/spack/lib/spack/spack/test/llnl/util/lang.py:308:5 - warning: Code is unreachable (reportUnreachable)
+   /tmp/mypy_primer/projects/spack/lib/spack/spack/test/llnl/util/lang.py:308:10 - warning: Type of "raises" is unknown (reportUnknownMemberType)
-   /tmp/mypy_primer/projects/spack/lib/spack/spack/test/llnl/util/lang.py:309:9 - warning: Code is unreachable (reportUnreachable)
-   /tmp/mypy_primer/projects/spack/lib/spack/spack/test/llnl/util/lang.py:310:13 - warning: Code is unreachable (reportUnreachable)
- 19507 errors, 300591 warnings, 0 notes
+ 19507 errors, 300588 warnings, 0 notes

arviz (https://github.com/arviz-devs/arviz): 4.92x slower (6.4s -> 31.3s in a single noisy sample)

@DetachHead DetachHead merged commit 10d8466 into main Dec 21, 2024
20 checks passed
@DetachHead DetachHead deleted the fix-contextmanager-exit-generic branch December 21, 2024 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant