-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
MNT: Deprecate changing Figure.number #29007
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
b51f0f2 to
fe63bd5
Compare
|
👍🏻 in principle, but we need tests. Do we want to leave public API for setting in the first time? |
|
Why are people overwriting the attribute if it "doesn't have the desired effect"? |
Either their own reasons or wishful API usage ;) |
lib/matplotlib/figure.py
Outdated
|
|
||
| @number.setter | ||
| def number(self, num): | ||
| _api.warn_deprecated("3.10", message="Changing 'Figure.number' is deprecated") |
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.
message needs %(since)s and %(removal)s.
|
If number is not to be used externally, why make it public at all? |
|
Digging into, there are only a few cases that are setting figure numbers:
I'm not clear why they do it, but we should not break them without prior warning.
Accessing or you keep a reference to the figure, in which case you can use the figure instead of the number: but since it is used as a core identifier, it feels right to be able to get the information |
a3bd0ab to
ea5b222
Compare
Historically, pyplot dynamically added a number attribute to figure. However, this number must stay in sync with the figure manger. AFAICS overwriting the number attribute does not have the desired effect for pyplot. But there are some repos in GitHub that do change number. So let's take it slow and properly migrate away from writing. Making the dynamic attribute private and wrapping it in a property allows to maintain current behavior and deprecate write-access. When the deprecation expires, there's no need for duplicate state anymore and the private _number attribute can be replaced by `self.canvas.manager.num` if that exists and None otherwise. Also closes matplotlib#28994.
Historically, pyplot dynamically added a
numberattribute to figure. However, this number must stay in sync with the figure manger. AFAICS overwriting the number attribute does not have the desired effect for pyplot. But there are some repos in GitHub that do change number. So let's take it slow and properly migrate away from writing.Making the dynamic attribute private and wrapping it in a property allows to maintain current behavior and deprecate write-access.
When the deprecation expires, there's no need for duplicate state anymore and the private _number attribute can be replaced by
return self.canvas.manager.numif that exists and None otherwise.Also closes #28994 (dynamic number attribute is not handled by type checkers).
@ksunden it would be nice to get this in for 3.10, but if that's too tight, feel free to move to 3.11.