File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2424import numpy as np
2525from matplotlib import _api , mlab
2626from matplotlib .axes import Axes
27+ from matplotlib .backend_bases import MouseButton
2728from matplotlib .figure import Figure
2829
2930
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+
3052# This is the magic line that must exist in pyplot, after which the boilerplate
3153# content will be appended.
3254PYPLOT_MAGIC_HEADER = (
You can’t perform that action at this time.
0 commit comments