Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 3 commits into from
Mar 13, 2018

Conversation

swfiua
Copy link
Contributor

@swfiua swfiua commented Mar 11, 2018

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.

@jklymak
Copy link
Member

jklymak commented Mar 11, 2018

This looks good, but I'd also change Text.__init__ to call set_verticalalignment so the error checking happens on init as well. As its written, the user could specify any thing in here...

@swfiua
Copy link
Contributor Author

swfiua commented Mar 11, 2018

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'?

"""
legal = ('top', 'bottom', 'center', 'baseline')
legal = ('top', 'bottom', 'center', 'baseline', 'centre_baseline')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Contributor Author

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;)

@jklymak
Copy link
Member

jklymak commented Mar 11, 2018

Is it just None that fails? If so maybe the call needs to be wrapped in an if verticalalignment is not None: and an else:? On the way out the door, so I didn't look at it carefully...

@swfiua
Copy link
Contributor Author

swfiua commented Mar 11, 2018

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.

@jklymak
Copy link
Member

jklymak commented Mar 11, 2018

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 set_verticalalignment should have a warning instead of throwing an error.

@jklymak
Copy link
Member

jklymak commented Mar 11, 2018

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 verticalalignment='RandomStuff'. I'm not personally so bothered by that because basically that code is buggy, but I'm not experienced enough about tightening API to know if thats a problem.

@jklymak jklymak added this to the v3.0 milestone Mar 11, 2018
Copy link
Member

@jklymak jklymak left a 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.

Copy link
Contributor

@dopplershift dopplershift left a 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.

@dopplershift dopplershift merged commit 8af1fac into matplotlib:master Mar 13, 2018
@swfiua swfiua deleted the cb branch May 27, 2019 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants