Skip to content

mypy 1.6.0 passing #8296

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

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ files = "xarray"
show_error_codes = true
show_error_context = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true

# Much of the numerical computing stack doesn't have type annotations yet.
Expand Down Expand Up @@ -168,26 +169,24 @@ module = [
# ref: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
[[tool.mypy.overrides]]
# Start off with these
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true

# Getting these passing should be easy
strict_equality = true
strict_concatenate = true
strict_equality = true

# Strongly recommend enabling this one as soon as you can
check_untyped_defs = true

# These shouldn't be too much additional work, but may be tricky to
# get passing if you use a lot of untyped libraries
disallow_any_generics = true
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true

# These next few are various gradations of forcing use of type annotations
disallow_untyped_calls = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_defs = true

# This one isn't too hard to get passing, but return on investment is lower
Expand All @@ -201,12 +200,12 @@ module = ["xarray.namedarray.*", "xarray.tests.test_namedarray"]
[tool.pyright]
# include = ["src"]
# exclude = ["**/node_modules",
# "**/__pycache__",
# "src/experimental",
# "src/typestubs"
# "**/__pycache__",
# "src/experimental",
# "src/typestubs"
# ]
# ignore = ["src/oldstuff"]
defineConstant = { DEBUG = true }
defineConstant = {DEBUG = true}
# stubPath = "src/stubs"
# venv = "env367"

Expand All @@ -217,10 +216,10 @@ reportMissingTypeStubs = false
# pythonPlatform = "Linux"

# executionEnvironments = [
# { root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", extraPaths = [ "src/service_libs" ] },
# { root = "src/sdk", pythonVersion = "3.0", extraPaths = [ "src/backend" ] },
# { root = "src/tests", extraPaths = ["src/tests/e2e", "src/sdk" ]},
# { root = "src" }
# { root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", extraPaths = [ "src/service_libs" ] },
# { root = "src/sdk", pythonVersion = "3.0", extraPaths = [ "src/backend" ] },
# { root = "src/tests", extraPaths = ["src/tests/e2e", "src/sdk" ]},
# { root = "src" }
# ]

[tool.ruff]
Expand Down Expand Up @@ -252,16 +251,16 @@ known-first-party = ["xarray"]

[tool.pytest.ini_options]
addopts = ["--strict-config", "--strict-markers"]
log_cli_level = "INFO"
minversion = "7"
filterwarnings = [
"ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
]
log_cli_level = "INFO"
markers = [
"flaky: flaky tests",
"network: tests requiring a network connection",
"slow: slow tests",
]
minversion = "7"
python_files = "test_*.py"
testpaths = ["xarray/tests", "properties"]

Expand Down
74 changes: 37 additions & 37 deletions xarray/core/_typed_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import operator
from typing import TYPE_CHECKING, Any, Callable, NoReturn, overload
from typing import TYPE_CHECKING, Any, Callable, overload

from xarray.core import nputils, ops
from xarray.core.types import (
Expand Down Expand Up @@ -446,201 +446,201 @@ def _binary_op(
raise NotImplementedError

@overload
def __add__(self, other: T_DataArray) -> NoReturn:
def __add__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __add__(self, other: VarCompatible) -> Self:
...

def __add__(self, other: VarCompatible) -> Self:
def __add__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.add)

@overload
def __sub__(self, other: T_DataArray) -> NoReturn:
def __sub__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __sub__(self, other: VarCompatible) -> Self:
...

def __sub__(self, other: VarCompatible) -> Self:
def __sub__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.sub)

@overload
def __mul__(self, other: T_DataArray) -> NoReturn:
def __mul__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __mul__(self, other: VarCompatible) -> Self:
...

def __mul__(self, other: VarCompatible) -> Self:
def __mul__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.mul)

@overload
def __pow__(self, other: T_DataArray) -> NoReturn:
def __pow__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __pow__(self, other: VarCompatible) -> Self:
...

def __pow__(self, other: VarCompatible) -> Self:
def __pow__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.pow)

@overload
def __truediv__(self, other: T_DataArray) -> NoReturn:
def __truediv__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __truediv__(self, other: VarCompatible) -> Self:
...

def __truediv__(self, other: VarCompatible) -> Self:
def __truediv__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.truediv)

@overload
def __floordiv__(self, other: T_DataArray) -> NoReturn:
def __floordiv__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __floordiv__(self, other: VarCompatible) -> Self:
...

def __floordiv__(self, other: VarCompatible) -> Self:
def __floordiv__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.floordiv)

@overload
def __mod__(self, other: T_DataArray) -> NoReturn:
def __mod__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __mod__(self, other: VarCompatible) -> Self:
...

def __mod__(self, other: VarCompatible) -> Self:
def __mod__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.mod)

@overload
def __and__(self, other: T_DataArray) -> NoReturn:
def __and__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __and__(self, other: VarCompatible) -> Self:
...

def __and__(self, other: VarCompatible) -> Self:
def __and__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.and_)

@overload
def __xor__(self, other: T_DataArray) -> NoReturn:
def __xor__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __xor__(self, other: VarCompatible) -> Self:
...

def __xor__(self, other: VarCompatible) -> Self:
def __xor__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.xor)

@overload
def __or__(self, other: T_DataArray) -> NoReturn:
def __or__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __or__(self, other: VarCompatible) -> Self:
...

def __or__(self, other: VarCompatible) -> Self:
def __or__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.or_)

@overload
def __lshift__(self, other: T_DataArray) -> NoReturn:
def __lshift__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __lshift__(self, other: VarCompatible) -> Self:
...

def __lshift__(self, other: VarCompatible) -> Self:
def __lshift__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.lshift)

@overload
def __rshift__(self, other: T_DataArray) -> NoReturn:
def __rshift__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __rshift__(self, other: VarCompatible) -> Self:
...

def __rshift__(self, other: VarCompatible) -> Self:
def __rshift__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.rshift)

@overload
def __lt__(self, other: T_DataArray) -> NoReturn:
def __lt__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __lt__(self, other: VarCompatible) -> Self:
...

def __lt__(self, other: VarCompatible) -> Self:
def __lt__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.lt)

@overload
def __le__(self, other: T_DataArray) -> NoReturn:
def __le__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __le__(self, other: VarCompatible) -> Self:
...

def __le__(self, other: VarCompatible) -> Self:
def __le__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.le)

@overload
def __gt__(self, other: T_DataArray) -> NoReturn:
def __gt__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __gt__(self, other: VarCompatible) -> Self:
...

def __gt__(self, other: VarCompatible) -> Self:
def __gt__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.gt)

@overload
def __ge__(self, other: T_DataArray) -> NoReturn:
def __ge__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __ge__(self, other: VarCompatible) -> Self:
...

def __ge__(self, other: VarCompatible) -> Self:
def __ge__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, operator.ge)

@overload # type:ignore[override]
def __eq__(self, other: T_DataArray) -> NoReturn:
def __eq__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __eq__(self, other: VarCompatible) -> Self:
...

def __eq__(self, other: VarCompatible) -> Self:
def __eq__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, nputils.array_eq)

@overload # type:ignore[override]
def __ne__(self, other: T_DataArray) -> NoReturn:
def __ne__(self, other: T_DataArray) -> T_DataArray:
...

@overload
def __ne__(self, other: VarCompatible) -> Self:
...

def __ne__(self, other: VarCompatible) -> Self:
def __ne__(self, other: VarCompatible) -> Self | T_DataArray:
return self._binary_op(other, nputils.array_ne)

def __radd__(self, other: VarCompatible) -> Self:
Expand Down
Loading