File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -2032,21 +2032,21 @@ def _setattr_cm(obj, **kwargs):
2032
2032
Temporarily set some attributes; restore original state at context exit.
2033
2033
"""
2034
2034
sentinel = object ()
2035
- origs = [(attr , getattr (obj , attr , sentinel )) for attr in kwargs ]
2036
2035
2037
2036
# we only want to set back things that are in the instance dict or
2038
2037
# are properties. Everything else we are either introducing to begin with
2039
2038
# 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 )
2043
2041
2042
+ if attr in obj .__dict__ :
2043
+ return val
2044
2044
if isinstance (getattr (type (obj ), attr ), property ):
2045
- return True
2046
- return False
2045
+ return val
2046
+
2047
+ return sentinel
2047
2048
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 ]
2050
2050
try :
2051
2051
for attr , val in kwargs .items ():
2052
2052
setattr (obj , attr , val )
You can’t perform that action at this time.
0 commit comments