Skip to content

Commit 25e6e08

Browse files
max-sixtyheadtr1ck
andauthored
Most of mypy 1.6.0 passing (#8296)
* Most of mypy 1.6.0 passing * fix typed ops --------- Co-authored-by: Michael Niklas <mick.niklas@gmail.com>
1 parent d50a5e5 commit 25e6e08

File tree

4 files changed

+67
-66
lines changed

4 files changed

+67
-66
lines changed

pyproject.toml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ files = "xarray"
7878
show_error_codes = true
7979
show_error_context = true
8080
warn_redundant_casts = true
81+
warn_unused_configs = true
8182
warn_unused_ignores = true
8283

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

175174
# Getting these passing should be easy
176-
strict_equality = true
177175
strict_concatenate = true
176+
strict_equality = true
178177

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

182181
# These shouldn't be too much additional work, but may be tricky to
183182
# get passing if you use a lot of untyped libraries
183+
disallow_any_generics = true
184184
disallow_subclassing_any = true
185185
disallow_untyped_decorators = true
186-
disallow_any_generics = true
187186

188187
# These next few are various gradations of forcing use of type annotations
189-
disallow_untyped_calls = true
190188
disallow_incomplete_defs = true
189+
disallow_untyped_calls = true
191190
disallow_untyped_defs = true
192191

193192
# This one isn't too hard to get passing, but return on investment is lower
@@ -201,12 +200,12 @@ module = ["xarray.namedarray.*", "xarray.tests.test_namedarray"]
201200
[tool.pyright]
202201
# include = ["src"]
203202
# exclude = ["**/node_modules",
204-
# "**/__pycache__",
205-
# "src/experimental",
206-
# "src/typestubs"
203+
# "**/__pycache__",
204+
# "src/experimental",
205+
# "src/typestubs"
207206
# ]
208207
# ignore = ["src/oldstuff"]
209-
defineConstant = { DEBUG = true }
208+
defineConstant = {DEBUG = true}
210209
# stubPath = "src/stubs"
211210
# venv = "env367"
212211

@@ -217,10 +216,10 @@ reportMissingTypeStubs = false
217216
# pythonPlatform = "Linux"
218217

219218
# executionEnvironments = [
220-
# { root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", extraPaths = [ "src/service_libs" ] },
221-
# { root = "src/sdk", pythonVersion = "3.0", extraPaths = [ "src/backend" ] },
222-
# { root = "src/tests", extraPaths = ["src/tests/e2e", "src/sdk" ]},
223-
# { root = "src" }
219+
# { root = "src/web", pythonVersion = "3.5", pythonPlatform = "Windows", extraPaths = [ "src/service_libs" ] },
220+
# { root = "src/sdk", pythonVersion = "3.0", extraPaths = [ "src/backend" ] },
221+
# { root = "src/tests", extraPaths = ["src/tests/e2e", "src/sdk" ]},
222+
# { root = "src" }
224223
# ]
225224

226225
[tool.ruff]
@@ -252,16 +251,16 @@ known-first-party = ["xarray"]
252251

253252
[tool.pytest.ini_options]
254253
addopts = ["--strict-config", "--strict-markers"]
255-
log_cli_level = "INFO"
256-
minversion = "7"
257254
filterwarnings = [
258255
"ignore:Using a non-tuple sequence for multidimensional indexing is deprecated:FutureWarning",
259256
]
257+
log_cli_level = "INFO"
260258
markers = [
261259
"flaky: flaky tests",
262260
"network: tests requiring a network connection",
263261
"slow: slow tests",
264262
]
263+
minversion = "7"
265264
python_files = "test_*.py"
266265
testpaths = ["xarray/tests", "properties"]
267266

xarray/core/_typed_ops.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from __future__ import annotations
55

66
import operator
7-
from typing import TYPE_CHECKING, Any, Callable, NoReturn, overload
7+
from typing import TYPE_CHECKING, Any, Callable, overload
88

99
from xarray.core import nputils, ops
1010
from xarray.core.types import (
@@ -446,201 +446,201 @@ def _binary_op(
446446
raise NotImplementedError
447447

448448
@overload
449-
def __add__(self, other: T_DataArray) -> NoReturn:
449+
def __add__(self, other: T_DataArray) -> T_DataArray:
450450
...
451451

452452
@overload
453453
def __add__(self, other: VarCompatible) -> Self:
454454
...
455455

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

459459
@overload
460-
def __sub__(self, other: T_DataArray) -> NoReturn:
460+
def __sub__(self, other: T_DataArray) -> T_DataArray:
461461
...
462462

463463
@overload
464464
def __sub__(self, other: VarCompatible) -> Self:
465465
...
466466

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

470470
@overload
471-
def __mul__(self, other: T_DataArray) -> NoReturn:
471+
def __mul__(self, other: T_DataArray) -> T_DataArray:
472472
...
473473

474474
@overload
475475
def __mul__(self, other: VarCompatible) -> Self:
476476
...
477477

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

481481
@overload
482-
def __pow__(self, other: T_DataArray) -> NoReturn:
482+
def __pow__(self, other: T_DataArray) -> T_DataArray:
483483
...
484484

485485
@overload
486486
def __pow__(self, other: VarCompatible) -> Self:
487487
...
488488

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

492492
@overload
493-
def __truediv__(self, other: T_DataArray) -> NoReturn:
493+
def __truediv__(self, other: T_DataArray) -> T_DataArray:
494494
...
495495

496496
@overload
497497
def __truediv__(self, other: VarCompatible) -> Self:
498498
...
499499

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

503503
@overload
504-
def __floordiv__(self, other: T_DataArray) -> NoReturn:
504+
def __floordiv__(self, other: T_DataArray) -> T_DataArray:
505505
...
506506

507507
@overload
508508
def __floordiv__(self, other: VarCompatible) -> Self:
509509
...
510510

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

514514
@overload
515-
def __mod__(self, other: T_DataArray) -> NoReturn:
515+
def __mod__(self, other: T_DataArray) -> T_DataArray:
516516
...
517517

518518
@overload
519519
def __mod__(self, other: VarCompatible) -> Self:
520520
...
521521

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

525525
@overload
526-
def __and__(self, other: T_DataArray) -> NoReturn:
526+
def __and__(self, other: T_DataArray) -> T_DataArray:
527527
...
528528

529529
@overload
530530
def __and__(self, other: VarCompatible) -> Self:
531531
...
532532

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

536536
@overload
537-
def __xor__(self, other: T_DataArray) -> NoReturn:
537+
def __xor__(self, other: T_DataArray) -> T_DataArray:
538538
...
539539

540540
@overload
541541
def __xor__(self, other: VarCompatible) -> Self:
542542
...
543543

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

547547
@overload
548-
def __or__(self, other: T_DataArray) -> NoReturn:
548+
def __or__(self, other: T_DataArray) -> T_DataArray:
549549
...
550550

551551
@overload
552552
def __or__(self, other: VarCompatible) -> Self:
553553
...
554554

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

558558
@overload
559-
def __lshift__(self, other: T_DataArray) -> NoReturn:
559+
def __lshift__(self, other: T_DataArray) -> T_DataArray:
560560
...
561561

562562
@overload
563563
def __lshift__(self, other: VarCompatible) -> Self:
564564
...
565565

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

569569
@overload
570-
def __rshift__(self, other: T_DataArray) -> NoReturn:
570+
def __rshift__(self, other: T_DataArray) -> T_DataArray:
571571
...
572572

573573
@overload
574574
def __rshift__(self, other: VarCompatible) -> Self:
575575
...
576576

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

580580
@overload
581-
def __lt__(self, other: T_DataArray) -> NoReturn:
581+
def __lt__(self, other: T_DataArray) -> T_DataArray:
582582
...
583583

584584
@overload
585585
def __lt__(self, other: VarCompatible) -> Self:
586586
...
587587

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

591591
@overload
592-
def __le__(self, other: T_DataArray) -> NoReturn:
592+
def __le__(self, other: T_DataArray) -> T_DataArray:
593593
...
594594

595595
@overload
596596
def __le__(self, other: VarCompatible) -> Self:
597597
...
598598

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

602602
@overload
603-
def __gt__(self, other: T_DataArray) -> NoReturn:
603+
def __gt__(self, other: T_DataArray) -> T_DataArray:
604604
...
605605

606606
@overload
607607
def __gt__(self, other: VarCompatible) -> Self:
608608
...
609609

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

613613
@overload
614-
def __ge__(self, other: T_DataArray) -> NoReturn:
614+
def __ge__(self, other: T_DataArray) -> T_DataArray:
615615
...
616616

617617
@overload
618618
def __ge__(self, other: VarCompatible) -> Self:
619619
...
620620

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

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

628628
@overload
629629
def __eq__(self, other: VarCompatible) -> Self:
630630
...
631631

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

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

639639
@overload
640640
def __ne__(self, other: VarCompatible) -> Self:
641641
...
642642

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

646646
def __radd__(self, other: VarCompatible) -> Self:

0 commit comments

Comments
 (0)