-
Notifications
You must be signed in to change notification settings - Fork 21
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
use a generic's bound when narrowing with isinstance
if it's covariant, or Never
if it's contravariant
#745
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
…ant, or `Never` if it's contravariant
13dd380
to
56f2fd5
Compare
This comment has been minimized.
This comment has been minimized.
5638235
to
6e30215
Compare
6e30215
to
2239619
Compare
This comment has been minimized.
This comment has been minimized.
2239619
to
69fb6f1
Compare
This comment has been minimized.
This comment has been minimized.
…hether to use variance to specialize type vars when narrowing
253fe90
to
d5ef6a7
Compare
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:237:13 - error: Type of "idx" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:237:19 - error: Type of "idx" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:238:20 - error: Type of "keys" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:239:21 - error: Type of "edits" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:240:13 - error: Type of "in_array" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:240:24 - error: Type of "in_array" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:241:21 - error: Type of "prev" is Any (reportAny)
- /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:273:21 - error: Result of call expression is of type "Unknown | None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
- /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:284:13 - error: Result of call expression is of type "Unknown | None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
- /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:290:13 - error: Type of "stack" is Any (reportAny)
+ /tmp/mypy_primer/projects/graphql-core/src/graphql/language/visitor.py:303:16 - error: Return type is Any (reportAny)
- 1860 errors, 0 warnings, 0 notes
+ 1865 errors, 0 warnings, 0 notes
anyio (https://github.com/agronholm/anyio)
- /tmp/mypy_primer/projects/anyio/src/anyio/_core/_exceptions.py:86:13 - error: Type of "exc" is partially unknown
- Type of "exc" is "Unknown | BaseExceptionGroup[Unknown]" (reportUnknownVariableType)
- /tmp/mypy_primer/projects/anyio/src/anyio/_core/_exceptions.py:86:20 - error: Type of "exceptions" is partially unknown
- Type of "exceptions" is "tuple[Unknown | BaseExceptionGroup[Unknown], ...]" (reportUnknownMemberType)
- /tmp/mypy_primer/projects/anyio/src/anyio/_core/_exceptions.py:87:43 - error: Argument type is partially unknown
- Argument corresponds to parameter "exception" in function "iterate_exceptions"
- Argument type is "Unknown | BaseExceptionGroup[Unknown]" (reportUnknownArgumentType)
- 1704 errors, 0 warnings, 0 notes
+ 1701 errors, 0 warnings, 0 notes
mypy (https://github.com/python/mypy)
- /tmp/mypy_primer/projects/mypy/mypy/server/objgraph.py:55:16 - error: Type of "e" is unknown (reportUnknownVariableType)
- /tmp/mypy_primer/projects/mypy/mypy/server/objgraph.py:55:31 - error: Argument type is partially unknown
- Argument corresponds to parameter "iterable" in function "__new__"
- Argument type is "Iterable[Unknown]" (reportUnknownArgumentType)
- /tmp/mypy_primer/projects/mypy/mypyc/analysis/ircheck.py:303:14 - error: Unnecessary isinstance call; "FrozenSet[object]" is always an instance of "frozenset[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/mypy/mypyc/analysis/ircheck.py:303:14 - error: Unnecessary isinstance call; "FrozenSet[object]" is always an instance of "frozenset[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/mypy/mypyc/codegen/literals.py:66:14 - error: Unnecessary isinstance call; "FrozenSet[object]" is always an instance of "frozenset[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/mypy/mypyc/codegen/literals.py:66:14 - error: Unnecessary isinstance call; "FrozenSet[object]" is always an instance of "frozenset[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/mypy/mypyc/codegen/literals.py:105:12 - error: Unnecessary isinstance call; "FrozenSet[object]" is always an instance of "frozenset[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/mypy/mypyc/codegen/literals.py:105:12 - error: Unnecessary isinstance call; "FrozenSet[object]" is always an instance of "frozenset[object]" (reportUnnecessaryIsInstance)
- 16227 errors, 0 warnings, 0 notes
+ 16225 errors, 0 warnings, 0 notes
sympy (https://github.com/sympy/sympy)
- /tmp/mypy_primer/projects/sympy/sympy/core/basic.py:351:24 - error: Argument type is unknown
- Argument corresponds to parameter "args" in function "__new__" (reportUnknownArgumentType)
- Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+ Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
- Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+ Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
- Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+ Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
- Type of "_" is "Unknown | Any | Literal[False]" (reportUnknownVariableType)
+ Type of "_" is "Unknown | Literal[False]" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:501:5 - error: Type of "eqs" is partially unknown
+ Type of "eqs" is "list[Unknown]" (reportUnknownVariableType)
- Argument type is "Unknown | Any | _NotImplementedType" (reportUnknownArgumentType)
+ Argument type is "Unknown | _NotImplementedType" (reportUnknownArgumentType)
- Type of "eqs" is "list[Unknown | Any]" (reportUnknownVariableType)
+ Type of "eqs" is "list[Unknown]" (reportUnknownVariableType)
- /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:505:16 - error: Argument type is partially unknown
+ /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:505:16 - error: Argument type is unknown
- Argument corresponds to parameter "iterable" in function "__init__"
+ Argument corresponds to parameter "iterable" in function "__init__" (reportUnknownArgumentType)
- Argument type is "Unknown | Any" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:717:18 - error: Argument type is unknown
+ Argument corresponds to parameter "f" in function "solve" (reportUnknownArgumentType)
- /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1768:5 - error: Type of "eqs" is partially unknown
+ /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1768:5 - error: Type of "eqs" is unknown (reportUnknownVariableType)
- Type of "eqs" is "Unknown | Any" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1769:18 - error: Argument type is unknown
+ Argument corresponds to parameter "f" in function "solve" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/sympy/sympy/solvers/tests/test_solvers.py:1770:18 - error: Argument type is unknown
+ Argument corresponds to parameter "f" in function "solve" (reportUnknownArgumentType)
- Type of "eq" is "_NotImplementedType | Unknown" (reportUnknownVariableType)
+ Type of "eq" is "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:236:16 - error: Operator "&" not supported for types "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" and "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality"
+ Operator "&" not supported for types "GreaterThan" and "LessThan"
+ Operator "&" not supported for types "GreaterThan" and "Equality"
+ Operator "&" not supported for types "GreaterThan" and "Relational"
+ Operator "&" not supported for types "GreaterThan" and "Unequality"
+ Operator "&" not supported for types "Equality" and "LessThan"
+ Operator "&" not supported for types "Equality" and "Equality"
+ Operator "&" not supported for types "Equality" and "Relational"
+ Operator "&" not supported for types "Equality" and "Unequality"
+ ... (reportOperatorIssue)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:425:16 - error: Operator "&" not supported for types "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" and "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality"
+ Operator "&" not supported for types "GreaterThan" and "LessThan"
+ Operator "&" not supported for types "GreaterThan" and "Equality"
+ Operator "&" not supported for types "GreaterThan" and "Relational"
+ Operator "&" not supported for types "GreaterThan" and "Unequality"
+ Operator "&" not supported for types "Equality" and "LessThan"
+ Operator "&" not supported for types "Equality" and "Equality"
+ Operator "&" not supported for types "Equality" and "Relational"
+ Operator "&" not supported for types "Equality" and "Unequality"
+ ... (reportOperatorIssue)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:713:17 - error: Operator "&" not supported for types "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" and "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality"
+ Operator "&" not supported for types "GreaterThan" and "LessThan"
+ Operator "&" not supported for types "GreaterThan" and "Equality"
+ Operator "&" not supported for types "GreaterThan" and "Relational"
+ Operator "&" not supported for types "GreaterThan" and "Unequality"
+ Operator "&" not supported for types "Equality" and "LessThan"
+ Operator "&" not supported for types "Equality" and "Equality"
+ Operator "&" not supported for types "Equality" and "Relational"
+ Operator "&" not supported for types "Equality" and "Unequality"
+ ... (reportOperatorIssue)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:771:22 - error: Invalid conditional operand of type "_NotImplementedType | StrictGreaterThan | Unknown | Equality | Relational | Unequality"
+ Method __bool__ for type "StrictGreaterThan" returns type "NoReturn" rather than "bool"
+ Method __bool__ for type "Equality" returns type "NoReturn" rather than "bool"
+ Method __bool__ for type "Relational" returns type "NoReturn" rather than "bool"
+ Method __bool__ for type "Unequality" returns type "NoReturn" rather than "bool" (reportGeneralTypeIssues)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:771:39 - error: Invalid conditional operand of type "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality"
+ Method __bool__ for type "LessThan" returns type "NoReturn" rather than "bool"
+ Method __bool__ for type "Equality" returns type "NoReturn" rather than "bool"
+ Method __bool__ for type "Relational" returns type "NoReturn" rather than "bool"
+ Method __bool__ for type "Unequality" returns type "NoReturn" rather than "bool" (reportGeneralTypeIssues)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:811:17 - error: Operator "&" not supported for types "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" and "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality"
+ Operator "&" not supported for types "GreaterThan" and "LessThan"
+ Operator "&" not supported for types "GreaterThan" and "Equality"
+ Operator "&" not supported for types "GreaterThan" and "Relational"
+ Operator "&" not supported for types "GreaterThan" and "Unequality"
+ Operator "&" not supported for types "Equality" and "LessThan"
+ Operator "&" not supported for types "Equality" and "Equality"
+ Operator "&" not supported for types "Equality" and "Relational"
+ Operator "&" not supported for types "Equality" and "Unequality"
+ ... (reportOperatorIssue)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/frv_types.py:814:17 - error: Operator "&" not supported for types "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" and "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality"
+ Operator "&" not supported for types "GreaterThan" and "LessThan"
+ Operator "&" not supported for types "GreaterThan" and "Equality"
+ Operator "&" not supported for types "GreaterThan" and "Relational"
+ Operator "&" not supported for types "GreaterThan" and "Unequality"
+ Operator "&" not supported for types "Equality" and "LessThan"
+ Operator "&" not supported for types "Equality" and "Equality"
+ Operator "&" not supported for types "Equality" and "Relational"
+ Operator "&" not supported for types "Equality" and "Unequality"
+ ... (reportOperatorIssue)
- Type of "condition" is "_NotImplementedType | Unknown" (reportUnknownVariableType)
+ Type of "condition" is "_NotImplementedType | StrictLessThan | Unknown | Equality | Relational | Unequality" (reportUnknownVariableType)
- Type of "condition" is "_NotImplementedType | Unknown" (reportUnknownVariableType)
+ Type of "condition" is "_NotImplementedType | StrictGreaterThan | Unknown | Equality | Relational | Unequality" (reportUnknownVariableType)
- Type of "condition" is "_NotImplementedType | Unknown" (reportUnknownVariableType)
+ Type of "condition" is "_NotImplementedType | LessThan | Unknown | Equality | Relational | Unequality" (reportUnknownVariableType)
- Type of "condition" is "_NotImplementedType | Unknown" (reportUnknownVariableType)
+ Type of "condition" is "_NotImplementedType | GreaterThan | Unknown | Equality | Relational | Unequality" (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/sympy/sympy/stats/tests/test_stochastic_process.py:126:14 - error: Operator "&" not supported for types "_NotImplementedType | StrictLessThan | Unknown | Equality | Relational | Unequality" and "_NotImplementedType | StrictGreaterThan | Unknown | Equality | Relational | Unequality"
+ Operator "&" not supported for types "StrictLessThan" and "StrictGreaterThan"
+ Operator "&" not supported for types "StrictLessThan" and "Equality"
... (truncated 63 lines) ...
websockets (https://github.com/aaugustin/websockets)
- /tmp/mypy_primer/projects/websockets/src/websockets/headers.py:470:12 - error: Unnecessary isinstance call; "Sequence[Subprotocol]" is always an instance of "Sequence[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/headers.py:470:12 - error: Unnecessary isinstance call; "Sequence[Subprotocol]" is always an instance of "Sequence[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/asyncio/connection.py:492:14 - error: Unnecessary isinstance call; "AsyncIterable[Data]" is always an instance of "AsyncIterable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/asyncio/connection.py:492:14 - error: Unnecessary isinstance call; "AsyncIterable[Data]" is always an instance of "AsyncIterable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/asyncio/server.py:901:14 - error: Unnecessary isinstance call; "tuple[str, str] | Iterable[tuple[str, str]]" is always an instance of "Iterable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/asyncio/server.py:901:14 - error: Unnecessary isinstance call; "tuple[str, str] | Iterable[tuple[str, str]]" is always an instance of "Iterable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/asyncio/server.py:951:12 - error: Unnecessary isinstance call; "bool" is never an instance of "Awaitable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/asyncio/server.py:951:12 - error: Unnecessary isinstance call; "bool" is never an instance of "Awaitable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/legacy/auth.py:162:14 - error: Unnecessary isinstance call; "Credentials | Iterable[Credentials]" is always an instance of "Iterable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/legacy/auth.py:162:14 - error: Unnecessary isinstance call; "Credentials | Iterable[Credentials]" is always an instance of "Iterable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/legacy/protocol.py:678:14 - error: Unnecessary isinstance call; "AsyncIterable[Data]" is always an instance of "AsyncIterable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/legacy/protocol.py:678:14 - error: Unnecessary isinstance call; "AsyncIterable[Data]" is always an instance of "AsyncIterable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/legacy/server.py:361:16 - error: Unnecessary isinstance call; "Awaitable[HTTPResponse | None]" is always an instance of "Awaitable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/legacy/server.py:361:16 - error: Unnecessary isinstance call; "Awaitable[HTTPResponse | None]" is always an instance of "Awaitable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/legacy/server.py:586:12 - error: Unnecessary isinstance call; "Coroutine[Any, Any, HTTPResponse | None]" is always an instance of "Awaitable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/legacy/server.py:586:12 - error: Unnecessary isinstance call; "Coroutine[Any, Any, HTTPResponse | None]" is always an instance of "Awaitable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/sync/connection.py:321:14 - error: Unnecessary isinstance call; "Iterable[Data]" is always an instance of "Iterable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/sync/connection.py:321:14 - error: Unnecessary isinstance call; "Iterable[Data]" is always an instance of "Iterable[object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/websockets/src/websockets/sync/server.py:668:14 - error: Unnecessary isinstance call; "tuple[str, str] | Iterable[tuple[str, str]]" is always an instance of "Iterable[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/websockets/src/websockets/sync/server.py:668:14 - error: Unnecessary isinstance call; "tuple[str, str] | Iterable[tuple[str, str]]" is always an instance of "Iterable[object]" (reportUnnecessaryIsInstance)
scikit-learn (https://github.com/scikit-learn/scikit-learn)
- /tmp/mypy_primer/projects/scikit-learn/sklearn/datasets/_samples_generator.py:1078:29 - error: Argument type is partially unknown
+ /tmp/mypy_primer/projects/scikit-learn/sklearn/datasets/_samples_generator.py:1078:25 - error: No overloads for "sum" match the provided arguments (reportCallIssue)
- Argument corresponds to parameter "iterable" in function "sum"
- Argument type is "<subclass of <subclass of int and Integral> and Iterable> | <subclass of int and Iterable> | list[int] | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/scikit-learn/sklearn/datasets/_samples_generator.py:1078:29 - error: Argument of type "<subclass of <subclass of int and Integral> and Iterable[object]> | <subclass of int and Iterable[object]> | list[int] | Unknown" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
+ Type "<subclass of <subclass of int and Integral> and Iterable[object]> | <subclass of int and Iterable[object]> | list[int] | Unknown" is not assignable to type "Iterable[_SupportsSumNoDefaultT@sum]"
+ "<subclass of <subclass of int and Integral> and Iterable[object]>" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
+ Type parameter "_T_co@Iterable" is covariant, but "object" is not a subtype of "_SupportsSumNoDefaultT@sum"
+ Type "object" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+ "object" is incompatible with protocol "_SupportsSumWithNoDefaultGiven" (reportArgumentType)
- /tmp/mypy_primer/projects/scikit-learn/sklearn/datasets/_samples_generator.py:1079:29 - error: Argument type is partially unknown
+ /tmp/mypy_primer/projects/scikit-learn/sklearn/datasets/_samples_generator.py:1079:25 - error: No overloads for "sum" match the provided arguments (reportCallIssue)
- Argument corresponds to parameter "iterable" in function "sum"
- Argument type is "<subclass of <subclass of int and Integral> and Iterable> | <subclass of int and Iterable> | list[int] | Unknown" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/scikit-learn/sklearn/datasets/_samples_generator.py:1079:29 - error: Argument of type "<subclass of <subclass of int and Integral> and Iterable[object]> | <subclass of int and Iterable[object]> | list[int] | Unknown" cannot be assigned to parameter "iterable" of type "Iterable[_SupportsSumNoDefaultT@sum]" in function "sum"
+ Type "<subclass of <subclass of int and Integral> and Iterable[object]> | <subclass of int and Iterable[object]> | list[int] | Unknown" is not assignable to type "Iterable[_SupportsSumNoDefaultT@sum]"
+ "<subclass of <subclass of int and Integral> and Iterable[object]>" is not assignable to "Iterable[_SupportsSumNoDefaultT@sum]"
+ Type parameter "_T_co@Iterable" is covariant, but "object" is not a subtype of "_SupportsSumNoDefaultT@sum"
+ Type "object" is not assignable to type "_SupportsSumWithNoDefaultGiven"
+ "object" is incompatible with protocol "_SupportsSumWithNoDefaultGiven" (reportArgumentType)
- Argument type is "<subclass of <subclass of int and Integral> and Iterable> | <subclass of int and Iterable> | list[int] | Unknown" (reportUnknownArgumentType)
+ Argument type is "<subclass of <subclass of int and Integral> and Iterable[object]> | <subclass of int and Iterable[object]> | list[int] | Unknown" (reportUnknownArgumentType)
- 208228 errors, 0 warnings, 0 notes
+ 208230 errors, 0 warnings, 0 notes
bidict (https://github.com/jab/bidict)
- Argument type is "Mapping[Unknown, Unknown]" (reportUnknownArgumentType)
+ Argument type is "Mapping[Unknown, object]" (reportUnknownArgumentType)
- Argument type is "zip[tuple[tuple[KT@BidictBase, VT@BidictBase], tuple[Unknown, Unknown]]]" (reportUnknownArgumentType)
+ Argument type is "zip[tuple[tuple[KT@BidictBase, VT@BidictBase], tuple[Unknown, object]]]" (reportUnknownArgumentType)
- Argument type is "ItemsView[Unknown, Unknown]" (reportUnknownArgumentType)
+ Argument type is "ItemsView[Unknown, object]" (reportUnknownArgumentType)
- /tmp/mypy_primer/projects/bidict/bidict/_base.py:423:16 - error: Unnecessary isinstance call; "MapOrItems[KT@BidictBase, VT@BidictBase]" is always an instance of "Iterable[Unknown] | Maplike[Unknown, Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/bidict/bidict/_base.py:423:16 - error: Unnecessary isinstance call; "MapOrItems[KT@BidictBase, VT@BidictBase]" is always an instance of "Iterable[object] | Maplike[Unknown, object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/bidict/bidict/_base.py:500:16 - error: Unnecessary isinstance call; "Mapping[KT@BidictBase, VT@BidictBase]" is always an instance of "Mapping[Unknown, Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/bidict/bidict/_base.py:500:16 - error: Unnecessary isinstance call; "Mapping[KT@BidictBase, VT@BidictBase]" is always an instance of "Mapping[Unknown, object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/bidict/bidict/_base.py:508:16 - error: Unnecessary isinstance call; "Mapping[KT@BidictBase, VT@BidictBase]" is always an instance of "Mapping[Unknown, Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/bidict/bidict/_base.py:508:16 - error: Unnecessary isinstance call; "Mapping[KT@BidictBase, VT@BidictBase]" is always an instance of "Mapping[Unknown, object]" (reportUnnecessaryIsInstance)
- /tmp/mypy_primer/projects/bidict/bidict/_base.py:543:12 - error: Return type, "Iterator[Unknown]", is partially unknown (reportUnknownVariableType)
+ /tmp/mypy_primer/projects/bidict/bidict/_base.py:543:12 - error: Type "Iterator[object]" is not assignable to return type "Iterator[KT@_fwdm_reversed]"
+ "Iterator[object]" is not assignable to "Iterator[KT@_fwdm_reversed]"
+ Type parameter "_T_co@Iterator" is covariant, but "object" is not a subtype of "KT@_fwdm_reversed"
+ Type "object" is not assignable to type "KT@_fwdm_reversed" (reportReturnType)
pydantic (https://github.com/pydantic/pydantic)
- /tmp/mypy_primer/projects/pydantic/pydantic/json_schema.py:1472:17 - error: Result of call expression is of type "Unknown | None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
+ /tmp/mypy_primer/projects/pydantic/pydantic/json_schema.py:1466:33 - error: Type of "__get__" is partially unknown
+ Type of "__get__" is "Overload[(instance: None, owner: type, /) -> ((...) -> object), (instance: _T@__get__, owner: type[_T@__get__] | None = None, /) -> ((...) -> object)] | Overload[(instance: Unknown, owner: type[Unknown] | None = None, /) -> ((...) -> object), (instance: None, owner: type[Unknown], /) -> ((...) -> object)]" (reportUnknownMemberType)
+ /tmp/mypy_primer/projects/pydantic/pydantic/json_schema.py:1466:33 - error: Type "(...) -> object" is not assignable to declared type "JsonSchemaExtraCallable | JsonDict | None"
+ Type "(...) -> object" is not assignable to type "JsonSchemaExtraCallable | JsonDict | None"
+ "function" is not assignable to "Dict[str, JsonValue]"
+ Type "(...) -> object" is not assignable to type "(JsonDict) -> None"
+ Function return type "object" is incompatible with type "None"
+ "object" is not assignable to "None"
+ Type "(...) -> object" is not assignable to type "(JsonDict, Type[Any]) -> None"
+ Function return type "object" is incompatible with type "None"
+ "object" is not assignable to "None"
+ ... (reportAssignmentType)
- /tmp/mypy_primer/projects/pydantic/pydantic/json_schema.py:1474:17 - error: Result of call expression is of type "Unknown | None" and is not used; assign to variable "_" if this is intentional (reportUnusedCallResult)
- /tmp/mypy_primer/projects/pydantic/pydantic/validate_call_decorator.py:54:25 - error: Argument type is partially unknown
- Argument corresponds to parameter "o" in function "__init__"
- Argument type is "staticmethod[..., Unknown]" (reportUnknownArgumentType)
- /tmp/mypy_primer/projects/pydantic/pydantic/_internal/_utils.py:258:14 - error: Unnecessary isinstance call; "AbstractSetIntStr" is always an instance of "AbstractSet[Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/pydantic/pydantic/_internal/_utils.py:258:14 - error: Unnecessary isinstance call; "AbstractSetIntStr" is always an instance of "AbstractSet[object]" (reportUnnecessaryIsInstance)
- 6214 errors, 0 warnings, 0 notes
+ 6213 errors, 0 warnings, 0 notes
scrapy (https://github.com/scrapy/scrapy)
+ /tmp/mypy_primer/projects/scrapy/scrapy/spiders/crawl.py:182:53 - error: Argument of type "List[object] | object | Any | tuple[()]" cannot be assigned to parameter "results" of type "Iterable[Any]" in function "process_results"
+ Type "List[object] | object | Any | tuple[()]" is not assignable to type "Iterable[Any]"
+ "object" is incompatible with protocol "Iterable[Any]"
+ "__iter__" is not present (reportArgumentType)
- /tmp/mypy_primer/projects/scrapy/scrapy/spiders/crawl.py:179:17 - error: Type of "cb_res" is partially unknown
- Type of "cb_res" is "List[Unknown]" (reportUnknownVariableType)
- /tmp/mypy_primer/projects/scrapy/scrapy/spiders/crawl.py:179:49 - error: Argument type is partially unknown
- Argument corresponds to parameter "result" in function "collect_asyncgen"
- Argument type is "AsyncIterable[Unknown]" (reportUnknownArgumentType)
- /tmp/mypy_primer/projects/scrapy/scrapy/spiders/crawl.py:181:17 - error: Type of "cb_res" is unknown (reportUnknownVariableType)
- /tmp/mypy_primer/projects/scrapy/scrapy/spiders/crawl.py:182:53 - error: Argument type is partially unknown
- Argument corresponds to parameter "results" in function "process_results"
- Argument type is "List[Unknown] | Unknown | Any | tuple[()]" (reportUnknownArgumentType)
- /tmp/mypy_primer/projects/scrapy/scrapy/utils/signal.py:39:15 - error: Argument type is partially unknown
- Argument corresponds to parameter "iterable" in function "__new__"
- Argument type is "Sequence[Unknown] | tuple[()]" (reportUnknownArgumentType)
+ /tmp/mypy_primer/projects/scrapy/scrapy/utils/signal.py:58:16 - error: "object" is not iterable
+ "__iter__" method not defined (reportGeneralTypeIssues)
+ /tmp/mypy_primer/projects/scrapy/scrapy/utils/signal.py:58:16 - error: "tuple[object, ...] | tuple[Any, ...]" is not a valid exception class (reportGeneralTypeIssues)
- 28442 errors, 0 warnings, 0 notes
+ 28440 errors, 0 warnings, 0 notes
core (https://github.com/home-assistant/core)
- /tmp/mypy_primer/projects/core/homeassistant/components/automation/config.py:226:8 - error: Unnecessary isinstance call; "dict[str, Any]" is always an instance of "Mapping[Unknown, Unknown]" (reportUnnecessaryIsInstance)
+ /tmp/mypy_primer/projects/core/homeassistant/components/automation/config.py:226:8 - error: Unnecessary isinstance call; "dict[str, Any]" is always an instance of "Mapping[Unknown, object]" (reportUnnecessaryIsInstance)
... (truncated 532 lines) ...``` |
def func4(var: ParentB[int]): | ||
if isinstance(var, ChildB1): | ||
reveal_type(var, expected_text="ChildB1[int]") | ||
reveal_type(var, expected_text="<subclass of ParentB[int] and ChildB1[float]>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem like a good change. If we already have a narrower type var, it seems like it shouldn't widen it.
Do you know an example where narrowing to ChildB1[int]
would be unsafe?
If it's just an issue of being difficult to implement, I think this change probably isn't bad enough to be a blocker.
Thanks for working on this. I tried working on it for a while, but I got stuck on trying to understand the code. |
i ran into a difficult to solve edge case that led to me abandoning this change for now (see the failing test case) but i may give it another go in the future |
fixes #674