From afcc560f3ea70dc9f3964dabf2b7632118f6085d Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Tue, 26 Sep 2023 15:05:25 -0500 Subject: [PATCH] [TYP] Remove some stubtest allowlist entries Mark the expected interface for some things such as Transform.input_dims as read-only via a property and remove redundant versions in subclasses Same for some offsetbox code Fix rcsetup ignores --- ci/mypy-stubtest-allowlist.txt | 18 ------------------ lib/matplotlib/offsetbox.pyi | 8 ++++++-- lib/matplotlib/rcsetup.pyi | 9 ++++++--- lib/matplotlib/transforms.pyi | 20 +++++++++----------- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/ci/mypy-stubtest-allowlist.txt b/ci/mypy-stubtest-allowlist.txt index e0890b3f7117..b92ef9c67688 100644 --- a/ci/mypy-stubtest-allowlist.txt +++ b/ci/mypy-stubtest-allowlist.txt @@ -32,18 +32,6 @@ matplotlib.ticker.LogitLocator.nonsingular matplotlib.backend_bases._Mode.__new__ matplotlib.units.Number.__hash__ -# Property read-write vs read-only weirdness, fix if possible -matplotlib.offsetbox.DraggableBase.canvas -matplotlib.offsetbox.DraggableBase.cids -matplotlib.transforms.BboxTransform.is_separable -matplotlib.transforms.BboxTransformFrom.is_separable -matplotlib.transforms.BboxTransformTo.is_separable -matplotlib.transforms.BlendedAffine2D.is_separable -matplotlib.transforms.CompositeGenericTransform.is_separable -matplotlib.transforms.TransformWrapper.input_dims -matplotlib.transforms.TransformWrapper.is_separable -matplotlib.transforms.TransformWrapper.output_dims - # 3.6 Pending deprecations matplotlib.figure.Figure.set_constrained_layout matplotlib.figure.Figure.set_constrained_layout_pads @@ -148,16 +136,10 @@ matplotlib.text.Text.set_weight matplotlib.axes._base._AxesBase.get_fc matplotlib.axes._base._AxesBase.set_fc -# Other dynamic python behaviors not type hinted -matplotlib.rcsetup.defaultParams - # Maybe should be abstractmethods, required for subclasses, stubs define once matplotlib.tri.*TriInterpolator.__call__ matplotlib.tri.*TriInterpolator.gradient -# Functionally a method call, but actually a class instance, type hinted as former -matplotlib.rcsetup.validate_fillstyle - # TypeVar used only in type hints matplotlib.backend_bases.FigureCanvasBase._T matplotlib.backend_managers.ToolManager._T diff --git a/lib/matplotlib/offsetbox.pyi b/lib/matplotlib/offsetbox.pyi index 09f89aed2bc8..c222a9b2973e 100644 --- a/lib/matplotlib/offsetbox.pyi +++ b/lib/matplotlib/offsetbox.pyi @@ -280,11 +280,15 @@ class AnnotationBbox(martist.Artist, mtext._AnnotationBase): class DraggableBase: ref_artist: martist.Artist got_artist: bool - canvas: FigureCanvasBase - cids: list[int] mouse_x: int mouse_y: int background: Any + + @property + def canvas(self) -> FigureCanvasBase: ... + @property + def cids(self) -> list[int]: ... + def __init__(self, ref_artist: martist.Artist, use_blit: bool = ...) -> None: ... def on_motion(self, evt: Event) -> None: ... def on_pick(self, evt: Event) -> None: ... diff --git a/lib/matplotlib/rcsetup.pyi b/lib/matplotlib/rcsetup.pyi index 8a8a9e71d666..70e94a7694a9 100644 --- a/lib/matplotlib/rcsetup.pyi +++ b/lib/matplotlib/rcsetup.pyi @@ -129,9 +129,9 @@ def validate_fontstretch( def validate_font_properties(s: Any) -> dict[str, Any]: ... def validate_whiskers(s: Any) -> list[float] | float: ... def validate_ps_distiller(s: Any) -> None | Literal["ghostscript", "xpdf"]: ... -def validate_fillstyle( - s: Any, -) -> Literal["full", "left", "right", "bottom", "top", "none"]: ... + +validate_fillstyle: ValidateInStrings + def validate_fillstylelist( s: Any, ) -> list[Literal["full", "left", "right", "bottom", "top", "none"]]: ... @@ -152,3 +152,6 @@ def validate_hist_bins( ) -> Literal["auto", "sturges", "fd", "doane", "scott", "rice", "sqrt"] | int | list[ float ]: ... + +# At runtime is added in __init__.py +defaultParams: dict[str, Any] diff --git a/lib/matplotlib/transforms.pyi b/lib/matplotlib/transforms.pyi index 68e55612b7f1..90a527e5bfc5 100644 --- a/lib/matplotlib/transforms.pyi +++ b/lib/matplotlib/transforms.pyi @@ -175,12 +175,17 @@ class LockableBbox(BboxBase): def locked_y1(self, y1: float | None) -> None: ... class Transform(TransformNode): - input_dims: int | None - output_dims: int | None - is_separable: bool - # Implemented as a standard attr in base class, but functionally readonly and some subclasses implement as such + + # Implemented as a standard attrs in base class, but functionally readonly and some subclasses implement as such + @property + def input_dims(self) -> int | None: ... + @property + def output_dims(self) -> int | None: ... + @property + def is_separable(self) -> bool: ... @property def has_inverse(self) -> bool: ... + def __add__(self, other: Transform) -> Transform: ... @property def depth(self) -> int: ... @@ -225,8 +230,6 @@ class Affine2DBase(AffineBase): input_dims: Literal[2] output_dims: Literal[2] def frozen(self) -> Affine2D: ... - @property - def is_separable(self): ... def to_values(self) -> tuple[float, float, float, float, float, float]: ... class Affine2D(Affine2DBase): @@ -255,7 +258,6 @@ class _BlendedMixin: class BlendedGenericTransform(_BlendedMixin, Transform): input_dims: Literal[2] output_dims: Literal[2] - is_separable: bool pass_through: bool def __init__( self, x_transform: Transform, y_transform: Transform, **kwargs @@ -265,8 +267,6 @@ class BlendedGenericTransform(_BlendedMixin, Transform): def contains_branch(self, other: Transform) -> Literal[False]: ... @property def is_affine(self) -> bool: ... - @property - def has_inverse(self) -> bool: ... class BlendedAffine2D(_BlendedMixin, Affine2DBase): def __init__( @@ -279,8 +279,6 @@ def blended_transform_factory( class CompositeGenericTransform(Transform): pass_through: bool - input_dims: int | None - output_dims: int | None def __init__(self, a: Transform, b: Transform, **kwargs) -> None: ... class CompositeAffine2D(Affine2DBase):