Skip to content

Commit 1ae9778

Browse files
authored
improve typing of OrderedSet (#4774)
* improve typing of OrderedSet * change Any to Hashable
1 parent 01a0faf commit 1ae9778

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

xarray/core/missing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ def interp(var, indexes_coords, method, **kwargs):
651651
out_dims.update(indexes_coords[d][1].dims)
652652
else:
653653
out_dims.add(d)
654-
result = result.transpose(*tuple(out_dims))
654+
result = result.transpose(*out_dims)
655655
return result
656656

657657

xarray/core/utils.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import warnings
1010
from enum import Enum
1111
from typing import (
12-
AbstractSet,
1312
Any,
1413
Callable,
1514
Collection,
@@ -509,17 +508,14 @@ class OrderedSet(MutableSet[T]):
509508

510509
__slots__ = ("_d",)
511510

512-
def __init__(self, values: AbstractSet[T] = None):
511+
def __init__(self, values: Iterable[T] = None):
513512
self._d = {}
514513
if values is not None:
515-
# Disable type checking - both mypy and PyCharm believe that
516-
# we're altering the type of self in place (see signature of
517-
# MutableSet.__ior__)
518-
self |= values # type: ignore
514+
self.update(values)
519515

520516
# Required methods for MutableSet
521517

522-
def __contains__(self, value: object) -> bool:
518+
def __contains__(self, value: Hashable) -> bool:
523519
return value in self._d
524520

525521
def __iter__(self) -> Iterator[T]:
@@ -536,9 +532,9 @@ def discard(self, value: T) -> None:
536532

537533
# Additional methods
538534

539-
def update(self, values: AbstractSet[T]) -> None:
540-
# See comment on __init__ re. type checking
541-
self |= values # type: ignore
535+
def update(self, values: Iterable[T]) -> None:
536+
for v in values:
537+
self._d[v] = None
542538

543539
def __repr__(self) -> str:
544540
return "{}({!r})".format(type(self).__name__, list(self))

0 commit comments

Comments
 (0)