-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
make centre_baseline legal for Text.set_verticalalignment #10751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This looks good, but I'd also change |
Fixing the init() to call the setters may break some code (it breaks the tests for now) since some code seems to rely on invalid verticalalignment in the constructor resulting in 'bottom' alignment. Not sure if it is wise to fix this. Perhaps just handle the special case None and map that to 'bottom'? |
lib/matplotlib/text.py
Outdated
""" | ||
legal = ('top', 'bottom', 'center', 'baseline') | ||
legal = ('top', 'bottom', 'center', 'baseline', 'centre_baseline') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UK English, my UK fingers find it difficult to type center;)
Is it just |
Re: is it just None that fails. Absolutey not -- just that None is the most likely value to turn up. In current code any value not in the legal list ends up results in the code for 'bottom' being used in _get_layout() In short, there is a choice between fixing the init method to use the setter or not risking breaking any existing code. |
My personal opinion is that the setter and the kwarg should have the same level of error checking, and I prefer the stronger error checking to no error checking. If there is to be no error checking, then |
Sorry, I shouldn't comment from my phone: I don't see that this change breaks any tests. OTOH, you are correct that it will break any code that has passed in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the correct solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silently accepting garbage and replacing with 'bottom' was a bug, not API. This is definitely better.
PR Summary
At some point in the past code was added to text.py to allow vertical alignment of text by centering on the baseline.
However, 'centre_baseline' is not a legal value for the set_verticalalignment() method.
This does not stop text using centre_baseline: you can supply the value as an argument when a Text object is created.
My guess is the option was added but the set_verticalalignment() method was overloooked.
If there is some other reason for hiding this option then the reason should be documented.
Perhaps the real fix here is to do something with type annotations rather than have the list of legal values in the code.