[TYP] Type changes from running against Pandas#26883
[TYP] Type changes from running against Pandas#26883timhoffm merged 3 commits intomatplotlib:mainfrom
Conversation
|
Apparently stubtest doesn't like that I put |
|
|
||
| from ._axes import * | ||
| from ._axes import Axes as Subplot | ||
| from ._axes import Axes as Axes |
There was a problem hiding this comment.
Since that's the only thing in there, should we change the import in the .py file, too?
There was a problem hiding this comment.
I mean, logically yes, but technically at runtime more gets imported there, just not things we intend to re-export.
I was being a bit conservative here and only changing stub behavior (especially since the stubs didn't pick up Subplot as being exported, when it should be)
There was a problem hiding this comment.
I actually think __init__.py files (broadly) are good candidates for inlining type hints and just not having separate files: they are short, contain little to no actual function definitions, it's mostly imports and __all__ (which I'm also in favor of adding in more places)
fe9a8b0 to
0c6a3b0
Compare
| containers: list[Container] | ||
| callbacks: CallbackRegistry | ||
| child_axes: list[_AxesBase] |
There was a problem hiding this comment.
Looking at __clear, I see also legend_ and title that aren't here; should they be added as well? (The former appears in axes.pyi on Axes)
There was a problem hiding this comment.
I'd say those ones (and perhaps several of the existing attrs) should be made private (title there is already _[left|right]_title which are private, though the getters/setters are defined in _axes.py, not _base.py, for some reason, and not defined for secondary_axes, even though the attrs exist)
But I'll add them since they are by naming convention public (though I will also note that none of these attrs (aside from dataLim and viewLim) actually appear in the rendered docs, though several (trans[Axes,Scale,Limits,Data] come to mind) are referred to by examples, etc. Is that something we want to include in the rendered docs? cc @timhoffm, this is reminiscent of the discussions regarding plt.Axes/plt.Figure, but is different in that these are not imports and are instance attributes)
There was a problem hiding this comment.
ax.title is used in several tests as well as the lifecycle tutorial and tight_layout_guide
axes.legend_ is used outside of the axes module only in backend/qt_editor/figureoptions.py as far as I can tell through quick greps (and never in documentation)
timhoffm
left a comment
There was a problem hiding this comment.
The instance attributes are technically public. Documenting the types is consistent with our current public API. It’s a separate question, whether they should be public, and IMHO many shouldn’t. But that has to go through the deprecation cycle.
…883-on-v3.8.x Backport PR #26883 on branch v3.8.x ([TYP] Type changes from running against Pandas)
PR summary
This is a few typing related changes identified by running against Pandas
ArtistListgeneric so that Axes properties can be type narrowed__clear, rather than__init__directly, so they are available on all Axes, but were missed when looking for attrsAdd a__all__toaxes/__init__.pyiaxes/__init__.pyihandles imports/re-exportingSubplot_AxisWrapperto type hint forTickHelper.set_axisAxisWrapperis set in Polar code and flags if absent herex.set_axis(x.axis)type checks as OKAnyPR checklist