Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit65e6fe4

Browse files
tacaswellQuLogic
andcommitted
MNT: Also handle general descriptors in _setattor_cm
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parenta436253 commit65e6fe4

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

‎lib/matplotlib/cbook/__init__.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
importcontextlib
1212
importfunctools
1313
importgzip
14+
importinspect
1415
importitertools
1516
importmath
1617
importoperator
@@ -1961,6 +1962,10 @@ def _array_patch_perimeters(x, rstride, cstride):
19611962
def_setattr_cm(obj,**kwargs):
19621963
"""
19631964
Temporarily set some attributes; restore original state at context exit.
1965+
1966+
.. warning ::
1967+
1968+
This is not threadsafe.
19641969
"""
19651970
sentinel=object()
19661971
origs= {}
@@ -1978,14 +1983,18 @@ def _setattr_cm(obj, **kwargs):
19781983
# we want to set the original value back.
19791984
ifisinstance(cls_orig,property):
19801985
origs[attr]=orig
1986+
1987+
# detect when we have Python Descriptors that supports
1988+
# setting so we will need to restore it
1989+
#
1990+
# https://docs.python.org/3/howto/descriptor.html
1991+
ifhasattr(inspect.getattr_static(type(obj),attr),'__set__'):
1992+
origs[attr]=orig
1993+
19811994
# otherwise this is _something_ we are going to shadow at
19821995
# the instance dict level from higher up in the MRO. We
19831996
# are going to assume we can delattr(obj, attr) to clean
1984-
# up after ourselves. It is possible that this code will
1985-
# fail if used with a non-property custom descriptor which
1986-
# implements __set__ (and __delete__ does not act like a
1987-
# stack). However, this is an internal tool and we do not
1988-
# currently have any custom descriptors.
1997+
# up after ourselves.
19891998
else:
19901999
origs[attr]=sentinel
19912000

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp