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 strictGenericNarrowing causing false positive reportUnnecessaryIsInstance errors when narrowing Callable #909

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DetachHead
Copy link
Owner

fixes #905

This comment has been minimized.

…yIsInstance` errors when narrowing `Callable`
@DetachHead DetachHead force-pushed the fix-strictGenericNarrowing-with-Callable branch from 277696c to fcced9f Compare November 27, 2024 09:05
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 "rootof" is "(f: Unknown, x: Unknown, index: Unknown | None = None, radicals: bool = True, expand: bool = True) -> (Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Expr)" (reportUnknownVariableType)
+     Type of "rootof" is "(f: Unknown, x: Unknown, index: Unknown | None = None, radicals: bool = True, expand: bool = True) -> (Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Expr)" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_inequalities.py:134:9 - warning: Type of "inf" is partially unknown
+     Type of "inf" is "One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Unknown" (reportUnknownVariableType)
-     Type of "r" is "Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Expr" (reportUnknownVariableType)
+     Type of "r" is "Unknown | One | NegativeOne | Zero | Integer | Rational | NaN | ComplexInfinity | Half | Expr" (reportUnknownVariableType)
-     Type of "factor" is "(f: Unknown, ..., deep: bool = False) -> (Unknown | Add | Order | Mul)" (reportUnknownVariableType)
+     Type of "factor" is "(f: Unknown, ..., deep: bool = False) -> (Unknown | Add | Order | Mul | Expr)" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_recurr.py:116:5 - warning: Type of "h" is partially unknown
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_recurr.py:116:5 - warning: Type of "h" is unknown (reportUnknownVariableType)
-     Type of "h" is "Any | Unknown" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:104:9 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any | bool], Any]", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:104:9 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any], Any]", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:105:13 - warning: Return type, "Integer | Unknown | NaN | Expr | One | NegativeOne | Zero | Rational | ComplexInfinity | Half", is partially unknown (reportUnknownParameterType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:109:20 - warning: Return type, "Unknown | NaN | Expr | One | NegativeOne | Zero | Integer | Rational | ComplexInfinity | Half", is partially unknown (reportUnknownVariableType)
-     Type of "constraints" is "list[_NotImplementedType | Unknown | Any | bool]" (reportUnknownVariableType)
+     Type of "constraints" is "list[_NotImplementedType | Unknown | Any]" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:111:29 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iterable" in function "sum"
+     Argument type is "Generator[Any | Unknown, None, None]" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:113:25 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iterable" in function "sum"
+     Argument type is "Generator[Any | Unknown, None, None]" (reportUnknownArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:114:16 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any | bool], Any]", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:114:16 - warning: Return type, "tuple[int, list[_NotImplementedType | Unknown | Any], Any]", is partially unknown (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:181:5 - warning: Type of "ans" is partially unknown
+     Type of "ans" is "tuple[Unknown, list[int | Unknown]]" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:221:9 - warning: Type of "ans" is partially unknown
+     Type of "ans" is "tuple[Unknown, list[int | Unknown]]" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:222:48 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iterable" in function "__init__"
+     Argument type is "zip[tuple[Any, int | Unknown]]" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:222:55 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iter2" in function "__new__"
+     Argument type is "list[int | Unknown]" (reportUnknownArgumentType)
-     Type of "ans" is "tuple[Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Half | Infinity | NegativeInfinity | Float | Number | Unknown | Order | int, list[int | ComplexInfinity | Rational | NaN | One | NegativeOne | Zero | Integer | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Expr]]" (reportUnknownVariableType)
+     Type of "ans" is "tuple[Unknown, list[int | Unknown]]" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:230:53 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iterable" in function "__init__"
+     Argument type is "zip[tuple[Any, int | Unknown]]" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:230:60 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iter2" in function "__new__"
+     Argument type is "list[int | Unknown]" (reportUnknownArgumentType)
-     Type of "ans" is "tuple[Expr | Rational | NaN | ComplexInfinity | One | NegativeOne | Zero | Integer | Half | Infinity | NegativeInfinity | Float | Number | Unknown | Order | int, list[int | ComplexInfinity | Rational | NaN | One | NegativeOne | Zero | Integer | Half | Infinity | NegativeInfinity | Float | _NotImplementedType | Expr]]" (reportUnknownVariableType)
+     Type of "ans" is "tuple[Unknown, list[int | Unknown]]" (reportUnknownVariableType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:236:53 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iterable" in function "__init__"
+     Argument type is "zip[tuple[Any, int | Unknown]]" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_simplex.py:236:60 - warning: Argument type is partially unknown
+     Argument corresponds to parameter "iter2" in function "__new__"
+     Argument type is "list[int | Unknown]" (reportUnknownArgumentType)
-     Type of "n" is "Unknown | Overload[(n: int = 15, subs: dict[Basic, Basic | float] | None = None, maxn: int = 100, chop: bool = False, strict: bool = False, quad: str | None = None, verbose: bool = False) -> Expr, (n: int = 15, subs: dict[Basic, Basic | float] | None = None, maxn: int = 100, chop: bool = False, strict: bool = False, quad: str | None = None, verbose: bool = False) -> Basic] | Any" (reportUnknownMemberType)
+     Type of "n" is "Unknown | Overload[(n: int = 15, subs: dict[Basic, Basic | float] | None = None, maxn: int = 100, chop: bool = False, strict: bool = False, quad: str | None = None, verbose: bool = False) -> Expr, (n: int = 15, subs: dict[Basic, Basic | float] | None = None, maxn: int = 100, chop: bool = False, strict: bool = False, quad: str | None = None, verbose: bool = False) -> Basic]" (reportUnknownMemberType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:479:5 - warning: Type of "sol" is partially unknown
+     Type of "sol" is "dict[Any, Unknown]" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1385:13 - warning: Argument type is Any
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1385:13 - warning: Argument type is unknown
-     Argument corresponds to parameter "lhs" in function "__new__" (reportAny)
+     Argument corresponds to parameter "lhs" in function "__new__" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1385:41 - warning: Argument type is unknown
+     Argument corresponds to parameter "rhs" in function "__new__" (reportUnknownArgumentType)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1563:5 - warning: Type of "answer" is partially unknown
+     Type of "answer" is "list[dict[Any, int] | dict[Any, int | Any | Unknown]]" (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:2498:23 - warning: Argument type is Any
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:2498:23 - warning: Argument type is unknown
-     Argument corresponds to parameter "args" in function "__new__" (reportAny)
+     Argument corresponds to parameter "args" in function "__new__" (reportUnknownArgumentType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:2507:5 - warning: Type of "eq" is Any (reportAny)
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:2507:5 - warning: Type of "eq" is unknown (reportUnknownVariableType)
-   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:2508:18 - warning: Argument type is Any
+   /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:2508:18 - warning: Argument type is unknown
-     Argument corresponds to parameter "eq" in function "unrad" (reportAny)
+     Argument corresponds to parameter "eq" in function "unrad" (reportUnknownArgumentType)

... (truncated 5146 lines) ...

mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
-   /tmp/mypy_primer/projects/mongo-python-driver/tools/convert_test_to_async.py:85:21 - warning: Unnecessary isinstance call; "(...) -> object" is never an instance of "classmethod[Unknown, ..., object]" (reportUnnecessaryIsInstance)
+   /tmp/mypy_primer/projects/mongo-python-driver/tools/convert_test_to_async.py:85:21 - warning: Unnecessary isinstance call; "(...) -> object" is never an instance of "classmethod[Unknown, ..., Unknown]" (reportUnnecessaryIsInstance)

asynq (https://github.com/quora/asynq): 196.68x slower (0.1s -> 12.5s in a single noisy sample)

kopf (https://github.com/nolar/kopf)
-   /tmp/mypy_primer/projects/kopf/kopf/_core/engines/admission.py:266:10 - warning: Unnecessary isinstance call; "WebhookServerProtocol" is never an instance of "AbstractAsyncContextManager[object, bool | None]" (reportUnnecessaryIsInstance)
+   /tmp/mypy_primer/projects/kopf/kopf/_core/engines/admission.py:266:10 - warning: Unnecessary isinstance call; "WebhookServerProtocol" is never an instance of "AbstractAsyncContextManager[Unknown, Unknown]" (reportUnnecessaryIsInstance)

vision (https://github.com/pytorch/vision): 1.59x slower (39.8s -> 63.3s in a single noisy sample)

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.

reportUnnecessaryIsInstance false positive with strictGenericNarrowing
1 participant