Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 96441b7

Browse files
committed
Return views for .keys(), .values(), .items()
1 parent 08192cd commit 96441b7

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

lib/matplotlib/__init__.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135

136136
import atexit
137137
from collections import namedtuple, ChainMap
138-
from collections.abc import MutableMapping, Mapping
138+
from collections.abc import MutableMapping, Mapping, KeysView, ValuesView, ItemsView
139139
import contextlib
140140
import functools
141141
import importlib
@@ -839,8 +839,13 @@ def __contains__(self, key):
839839

840840
def __iter__(self):
841841
"""Yield from sorted list of keys"""
842+
keys = (
843+
".".join((space, key))
844+
for space, mapping in self._namespace_maps.items()
845+
for key in mapping.keys()
846+
)
842847
with _api.suppress_matplotlib_deprecation_warning():
843-
yield from sorted(self.keys())
848+
yield from sorted(keys)
844849

845850
def __len__(self):
846851
return sum(len(mapping) for mapping in self._namespace_maps)
@@ -857,22 +862,6 @@ def __repr__(self):
857862
def __str__(self):
858863
return '\n'.join(map('{0[0]}: {0[1]}'.format, sorted(self.items())))
859864

860-
def keys(self):
861-
keys = (
862-
".".join((space, key))
863-
for space, mapping in self._namespace_maps.items()
864-
for key in mapping.keys()
865-
)
866-
return keys
867-
868-
def values(self):
869-
for key in self.keys():
870-
yield self[key]
871-
872-
def items(self):
873-
for key, value in zip(self.keys(), self.values()):
874-
yield key, value
875-
876865
def pop(self, key):
877866
keys, depth = self._split_key(key)
878867
if depth == 1:

lib/matplotlib/__init__.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,14 @@ class RcParams(MutableMapping):
7575
namespaces: tuple
7676
single_key_set: set
7777
def __init__(self, *args, **kwargs) -> None: ...
78-
def _split_key(self, key: str, sep: str = ".") -> tuple[list, int]: ...
78+
def _split_key(key: str, sep: str = ...) -> tuple[list, int]: ...
7979
def _set(self, key: str, val: Any) -> None: ...
8080
def _get(self, key: str) -> Any: ...
8181
def __setitem__(self, key: str, val: Any) -> None: ...
8282
def __getitem__(self, key: str) -> Any: ...
8383
def __delitem__(self, key: str) -> None: ...
8484
def __iter__(self) -> Generator[str, None, None]: ...
8585
def __len__(self) -> int: ...
86-
def keys(self) -> Generator[str, None, None]: ...
87-
def values(self) -> Generator[Any, None, None]: ...
8886
def find_all(self, pattern: str) -> RcParams: ...
8987
def copy(self) -> RcParams: ...
9088

0 commit comments

Comments
 (0)