-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Revisit the body of a loop if the number of partial types has changed. #18180
base: master
Are you sure you want to change the base?
Revisit the body of a loop if the number of partial types has changed. #18180
Conversation
# Conflicts: # test-data/unit/check-narrowing.test
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I went through the primer and this is looking great. 3-5 cases where ideally mypy would do something different, but may be technically unrelated to this PR (didn't look). operator: true positive |
@hauntsaninja: Thank you very much for looking so thoroughly through the primer! |
Diff from mypy_primer, showing the effect of this PR on open source code: operator (https://github.com/canonical/operator)
+ ops/lib/__init__.py:219: error: Argument 1 to "_Missing" has incompatible type "dict[str | Any, object]"; expected "bool" [arg-type]
manticore (https://github.com/trailofbits/manticore)
+ tests/wasm/json2mc.py:103: error: Invalid index type "int | None" for "list[Module]"; expected type "SupportsIndex" [index]
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/settings/legacy.py:105: note: Expected:
+ src/prefect/settings/legacy.py:105: note: def __hash__() -> int
+ src/prefect/settings/legacy.py:105: note: Got:
+ src/prefect/settings/legacy.py:105: note: def __hash__(self: object) -> int
+ src/prefect/cli/cloud/__init__.py:224: error: Incompatible return value type (got "str | tuple[Hashable, str]", expected "str") [return-value]
pylint (https://github.com/pycqa/pylint)
+ pylint/lint/message_state_handler.py:381: error: Need type annotation for "_ignore_file" [var-annotated]
xarray (https://github.com/pydata/xarray)
+ xarray/core/indexing.py: note: In member "__init__" of class "VectorizedIndexer":
+ xarray/core/indexing.py:488: error: Item "_arrayfunction[Any, Any]" of "_arrayfunction[Any, Any] | _arrayapi[Any, Any]" has no attribute "ndim" [union-attr]
+ xarray/core/indexing.py:488: error: Item "_arrayapi[Any, Any]" of "_arrayfunction[Any, Any] | _arrayapi[Any, Any]" has no attribute "ndim" [union-attr]
sympy (https://github.com/sympy/sympy)
+ sympy/tensor/array/expressions/from_array_to_matrix.py:398: error: Invalid index type "int | None" for "list[Any]"; expected type "SupportsIndex" [index]
+ sympy/tensor/array/expressions/from_array_to_matrix.py:401: error: Invalid index type "int | None" for "list[Any]"; expected type "SupportsIndex" [index]
comtypes (https://github.com/enthought/comtypes)
+ comtypes/tools/codegenerator/codegenerator.py:848: error: Unsupported operand types for | ("object" and "int") [operator]
+ comtypes/tools/codegenerator/codegenerator.py:850: error: Unsupported operand types for | ("object" and "int") [operator]
aiortc (https://github.com/aiortc/aiortc)
+ src/aiortc/jitterbuffer.py:81: error: "RtpPacket" has no attribute "_data" [attr-defined]
httpx-caching (https://github.com/johtso/httpx-caching)
+ httpx_caching/_policy.py:491: error: Incompatible types in assignment (expression has type "None", target has type "int") [assignment]
flake8 (https://github.com/pycqa/flake8)
+ src/flake8/processor.py:217: error: Unsupported operand types for - ("None" and "int") [operator]
+ src/flake8/processor.py:217: note: Left operand is of type "int | None"
jax (https://github.com/google/jax)
+ jax/_src/interpreters/pxla.py:2249: error: Item "AbstractMesh" of "Mesh | AbstractMesh" has no attribute "abstract_mesh" [union-attr]
+ jax/_src/interpreters/pxla.py:2253: error: Item "AbstractMesh" of "Mesh | AbstractMesh" has no attribute "abstract_mesh" [union-attr]
+ jax/_src/checkify.py:262: error: Value of type "int | Array" is not indexable [index]
poetry (https://github.com/python-poetry/poetry)
+ src/poetry/mixology/partial_solution.py:195: error: Incompatible types in assignment (expression has type "Term | None", variable has type "Assignment | None") [assignment]
pyodide (https://github.com/pyodide/pyodide)
+ src/py/pyodide/_state.py:21: error: Incompatible types in assignment (expression has type "pyodide._state.<subclass of "ModuleType" and "JsProxy">1", target has type "pyodide._state.<subclass of "ModuleType" and "JsProxy">") [assignment]
dulwich (https://github.com/dulwich/dulwich)
+ dulwich/config.py:558: error: Unsupported left operand type for + ("None") [operator]
+ dulwich/config.py:558: note: Left operand is of type "bytes | None"
+ dulwich/config.py:560: error: Unsupported left operand type for + ("None") [operator]
+ dulwich/config.py:560: note: Left operand is of type "bytes | None"
+ dulwich/config.py:562: error: Unsupported left operand type for + ("None") [operator]
+ dulwich/config.py:562: note: Left operand is of type "bytes | None"
|
I had a look at the false positive for from typing import Union, Tuple
def f() -> bool: ...
u: Union[int, Tuple[int]]
x = None
if f():
x = u
if isinstance(x, tuple):
x = x[0]
reveal_type(x) # N: Revealed type is "Union[builtins.int, Tuple[builtins.int], None]" (Tuple[builtins.int] should be narrowed away.) |
Fixes #5423