Skip to content
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

improve typing of OrderedSet #4774

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion xarray/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def interp(var, indexes_coords, method, **kwargs):
out_dims.update(indexes_coords[d][1].dims)
else:
out_dims.add(d)
result = result.transpose(*tuple(out_dims))
result = result.transpose(*out_dims)
return result


Expand Down
16 changes: 6 additions & 10 deletions xarray/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import warnings
from enum import Enum
from typing import (
AbstractSet,
Any,
Callable,
Collection,
Expand Down Expand Up @@ -509,17 +508,14 @@ class OrderedSet(MutableSet[T]):

__slots__ = ("_d",)

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

# Required methods for MutableSet

def __contains__(self, value: object) -> bool:
def __contains__(self, value: Any) -> bool:
rhkleijn marked this conversation as resolved.
Show resolved Hide resolved
return value in self._d

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

# Additional methods

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

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