FIX: MouseButton representation in boilerplate generated signatures #20148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Summary
In Python 3.10 the repr and str representation of Enums changed from
str: 'ClassName.NAME' -> 'NAME'
repr: '<ClassName.NAME: value>' -> 'ClassName.NAME'
which is more consistent with what str/repr should do, however this breaks
boilerplate which needs to get the ClassName.NAME version in all versions of
Python. Thus, we locally monkey patch our preferred str representation in
here.
bpo-40066
python/cpython#22392
Other options considered:
MouseButton.__str__
inmatplotlib.backend_bases
. This has the advantage of maintaining stability ofstr(MouseButton.Left)
over time, but this feels like something we should not fight upstream on. If they chose to break this intentionally we should follow them and not make our Enum "special"matplotlib/tools/boilerplate.py
Lines 122 to 125 in f6790c0
MouseButton
, but that would more-or-less involve vendoring the str methods from bothinspect.Signature
andinspect.Parameter
which are about a screen of code in total.PR Checklist
pytest
passes). (this fixes a failure on py310)flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).