diff options
Diffstat (limited to 'mesonbuild/mesonlib/universal.py')
-rw-r--r-- | mesonbuild/mesonlib/universal.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index f193889..1e3f54e 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -425,7 +425,7 @@ class File(HoldableObject): def suffix(self) -> str: return os.path.splitext(self.fname)[1][1:].lower() - def endswith(self, ending: str) -> bool: + def endswith(self, ending: T.Union[str, T.Tuple[str, ...]]) -> bool: return self.fname.endswith(ending) def split(self, s: str, maxsplit: int = -1) -> T.List[str]: @@ -1319,11 +1319,11 @@ def extract_as_list(dict_object: T.Dict[_T, _U], key: _T, pop: bool = False) -> ''' Extracts all values from given dict_object and listifies them. ''' - fetch = dict_object.get + fetch: T.Callable[[_T], _U] = dict_object.get if pop: fetch = dict_object.pop # If there's only one key, we don't return a list with one element - return listify(fetch(key, []), flatten=True) + return listify(fetch(key) or [], flatten=True) def typeslistify(item: 'T.Union[_T, T.Sequence[_T]]', @@ -1708,9 +1708,7 @@ class OrderedSet(T.MutableSet[_T]): insertion. """ def __init__(self, iterable: T.Optional[T.Iterable[_T]] = None): - # typing.OrderedDict is new in 3.7.2, so we can't use that, but we can - # use MutableMapping, which is fine in this case. - self.__container = collections.OrderedDict() # type: T.MutableMapping[_T, None] + self.__container: T.OrderedDict[_T, None] = collections.OrderedDict() if iterable: self.update(iterable) @@ -1741,12 +1739,10 @@ class OrderedSet(T.MutableSet[_T]): del self.__container[value] def move_to_end(self, value: _T, last: bool = True) -> None: - # Mypy does not know about move_to_end, because it is not part of MutableMapping - self.__container.move_to_end(value, last) # type: ignore + self.__container.move_to_end(value, last) def pop(self, last: bool = True) -> _T: - # Mypy does not know about the last argument, because it is not part of MutableMapping - item, _ = self.__container.popitem(last) # type: ignore + item, _ = self.__container.popitem(last) return item def update(self, iterable: T.Iterable[_T]) -> None: @@ -1756,6 +1752,10 @@ class OrderedSet(T.MutableSet[_T]): def difference(self, set_: T.Union[T.Set[_T], 'OrderedSet[_T]']) -> 'OrderedSet[_T]': return type(self)(e for e in self if e not in set_) + def difference_update(self, iterable: T.Iterable[_T]) -> None: + for item in iterable: + self.discard(item) + def relpath(path: str, start: str) -> str: # On Windows a relative path can't be evaluated for paths on two different # drives (i.e. c:\foo and f:\bar). The only thing left to do is to use the |