-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[TYP] Type changes from running against Pandas #26883
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ from matplotlib import cbook | |
from matplotlib.artist import Artist | ||
from matplotlib.axis import XAxis, YAxis, Tick | ||
from matplotlib.backend_bases import RendererBase, MouseButton, MouseEvent | ||
from matplotlib.cbook import CallbackRegistry | ||
from matplotlib.container import Container | ||
from matplotlib.collections import Collection | ||
from matplotlib.cm import ScalarMappable | ||
|
@@ -25,9 +26,11 @@ from cycler import Cycler | |
|
||
import numpy as np | ||
from numpy.typing import ArrayLike | ||
from typing import Any, Literal, overload | ||
from typing import Any, Literal, TypeVar, overload | ||
from matplotlib.typing import ColorType | ||
|
||
_T = TypeVar("_T", bound=Artist) | ||
|
||
class _axis_method_wrapper: | ||
attr_name: str | ||
method_name: str | ||
|
@@ -53,6 +56,11 @@ class _AxesBase(martist.Artist): | |
transData: Transform | ||
ignore_existing_data_limits: bool | ||
axison: bool | ||
containers: list[Container] | ||
callbacks: CallbackRegistry | ||
child_axes: list[_AxesBase] | ||
Comment on lines
+59
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say those ones (and perhaps several of the existing attrs) should be made private ( But I'll add them since they are by naming convention public (though I will also note that none of these attrs (aside from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
legend_: Legend | None | ||
title: Text | ||
_projection_init: Any | ||
|
||
def __init__( | ||
|
@@ -125,8 +133,7 @@ class _AxesBase(martist.Artist): | |
def clear(self) -> None: ... | ||
def cla(self) -> None: ... | ||
|
||
# Could be made generic, but comments indicate it may be temporary anyway | ||
class ArtistList(Sequence[Artist]): | ||
class ArtistList(Sequence[_T]): | ||
def __init__( | ||
self, | ||
axes: _AxesBase, | ||
|
@@ -135,40 +142,40 @@ class _AxesBase(martist.Artist): | |
invalid_types: type | Iterable[type] | None = ..., | ||
) -> None: ... | ||
def __len__(self) -> int: ... | ||
def __iter__(self) -> Iterator[Artist]: ... | ||
def __iter__(self) -> Iterator[_T]: ... | ||
@overload | ||
def __getitem__(self, key: int) -> Artist: ... | ||
def __getitem__(self, key: int) -> _T: ... | ||
@overload | ||
def __getitem__(self, key: slice) -> list[Artist]: ... | ||
def __getitem__(self, key: slice) -> list[_T]: ... | ||
|
||
@overload | ||
def __add__(self, other: _AxesBase.ArtistList) -> list[Artist]: ... | ||
def __add__(self, other: _AxesBase.ArtistList[_T]) -> list[_T]: ... | ||
@overload | ||
def __add__(self, other: list[Any]) -> list[Any]: ... | ||
@overload | ||
def __add__(self, other: tuple[Any]) -> tuple[Any]: ... | ||
|
||
@overload | ||
def __radd__(self, other: _AxesBase.ArtistList) -> list[Artist]: ... | ||
def __radd__(self, other: _AxesBase.ArtistList[_T]) -> list[_T]: ... | ||
@overload | ||
def __radd__(self, other: list[Any]) -> list[Any]: ... | ||
@overload | ||
def __radd__(self, other: tuple[Any]) -> tuple[Any]: ... | ||
|
||
@property | ||
def artists(self) -> _AxesBase.ArtistList: ... | ||
def artists(self) -> _AxesBase.ArtistList[Artist]: ... | ||
@property | ||
def collections(self) -> _AxesBase.ArtistList: ... | ||
def collections(self) -> _AxesBase.ArtistList[Collection]: ... | ||
@property | ||
def images(self) -> _AxesBase.ArtistList: ... | ||
def images(self) -> _AxesBase.ArtistList[AxesImage]: ... | ||
@property | ||
def lines(self) -> _AxesBase.ArtistList: ... | ||
def lines(self) -> _AxesBase.ArtistList[Line2D]: ... | ||
@property | ||
def patches(self) -> _AxesBase.ArtistList: ... | ||
def patches(self) -> _AxesBase.ArtistList[Patch]: ... | ||
@property | ||
def tables(self) -> _AxesBase.ArtistList: ... | ||
def tables(self) -> _AxesBase.ArtistList[Table]: ... | ||
@property | ||
def texts(self) -> _AxesBase.ArtistList: ... | ||
def texts(self) -> _AxesBase.ArtistList[Text]: ... | ||
def get_facecolor(self) -> ColorType: ... | ||
def set_facecolor(self, color: ColorType | None) -> None: ... | ||
@overload | ||
|
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)