Skip to content

Commit 9d5d10c

Browse files
tacaswellQuLogic
andauthored
MNT: merge loops
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent 9abe140 commit 9d5d10c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,21 +2032,21 @@ def _setattr_cm(obj, **kwargs):
20322032
Temporarily set some attributes; restore original state at context exit.
20332033
"""
20342034
sentinel = object()
2035-
origs = [(attr, getattr(obj, attr, sentinel)) for attr in kwargs]
20362035

20372036
# we only want to set back things that are in the instance dict or
20382037
# are properties. Everything else we are either introducing to begin with
20392038
# or are shadowing from something later in the resolution order.
2040-
def filter_restores(obj, attr, val):
2041-
if attr in obj.__dict__:
2042-
return True
2039+
def get_filtered_attr(obj, attr):
2040+
val = getattr(obj, attr, sentinel)
20432041

2042+
if attr in obj.__dict__:
2043+
return val
20442044
if isinstance(getattr(type(obj), attr), property):
2045-
return True
2046-
return False
2045+
return val
2046+
2047+
return sentinel
20472048

2048-
origs = [(attr, val if filter_restores(obj, attr, val) else sentinel)
2049-
for attr, val in origs]
2049+
origs = [(attr, get_filtered_attr(obj, attr)) for attr in kwargs]
20502050
try:
20512051
for attr, val in kwargs.items():
20522052
setattr(obj, attr, val)

0 commit comments

Comments
 (0)