File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 24
24
import numpy as np
25
25
from matplotlib import _api , mlab
26
26
from matplotlib .axes import Axes
27
+ from matplotlib .backend_bases import MouseButton
27
28
from matplotlib .figure import Figure
28
29
29
30
31
+ # we need to define a custom str because py310 change
32
+ # In Python 3.10 the repr and str representation of Enums changed from
33
+ #
34
+ # str: 'ClassName.NAME' -> 'NAME'
35
+ # repr: '<ClassName.NAME: value>' -> 'ClassName.NAME'
36
+ #
37
+ # which is more consistent with what str/repr should do, however this breaks
38
+ # boilerplate which needs to get the ClassName.NAME version in all versions of
39
+ # Python. Thus, we locally monkey patch our preferred str representation in
40
+ # here.
41
+ #
42
+ # bpo-40066
43
+ # https://github.com/python/cpython/pull/22392/
44
+ def enum_str_back_compat_patch (self ):
45
+ return f'{ type (self ).__name__ } .{ self .name } '
46
+
47
+ # only monkey patch if we have to.
48
+ if str (MouseButton .LEFT ) != 'MouseButton.Left' :
49
+ MouseButton .__str__ = enum_str_back_compat_patch
50
+
51
+
30
52
# This is the magic line that must exist in pyplot, after which the boilerplate
31
53
# content will be appended.
32
54
PYPLOT_MAGIC_HEADER = (
You can’t perform that action at this time.
0 commit comments