Skip to content

Conversation

@ABarpanda
Copy link

@ABarpanda ABarpanda commented Oct 31, 2025

PR summary

This PR adds a new type stub file for mpl_toolkits.mplot3d.axes3d and makes minor improvements to type hints in matplotlib.axes._base.

  • Added axes3d.pyi with type definitions for Axes3D, _Quaternion, and get_test_data.

  • Updated _base.py and _base.pyi with more explicit annotations for _shared_axes and _twinned_axes.

  • Since there are no dedicated test files for these modules, pytest could not be used.

  • Type checking was done using mypy; remaining errors are from inherited parent classes, not the new additions.

PR checklist

Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

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

You will need to fix the linting errors. There are also a lot of Any; I'm not sure how helpful the type hints are with so many of them.

import numpy as np
from numpy.typing import ArrayLike
from typing import Any, Literal, TypeVar, overload
from typing import Any, Literal, TypeVar, overload, List
Copy link
Member

Choose a reason for hiding this comment

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

We don't use these deprecated aliases; you should be using list.

Comment on lines +48 to +50
def __init__(self, bounds: Sequence[float], transform: Transform) -> None: ...

def __call__(self, ax: Any, renderer: Any) -> Bbox: ...
Copy link
Member

Choose a reason for hiding this comment

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

Don't need the blank lines between methods in type stubs.

title: Text
_axis_map: dict[str, Axis]
_projection_init: Any
_axis_names: tuple[Literal['x'], Literal['y']] | tuple[Literal['x'], Literal['y'], Literal['z']]
Copy link
Member

Choose a reason for hiding this comment

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

This type is definitely not literals.

Copy link
Member

Choose a reason for hiding this comment

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

@QuLogic not sure. I think right now this is true at least within the core library. At least PolarAxes still has ("x", "y") whether that is desirable is another topic.

fig : Figure
The parent figure.
rect : tuple (left, bottom, width, height), default: (0, 0, 1, 1)
rect : tuple (left, bottom, width, height), default: None
Copy link
Member

Choose a reason for hiding this comment

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

This change is unrelated, and incorrect.

Copy link
Member

Choose a reason for hiding this comment

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

Please revert. Defaults stated in the docstring are the logical defaults, not necessary what's formally given as the default placeholder object.

from __future__ import annotations
__all__ = ["Axes3D", "_Quaternion", "get_test_data"]

from typing import Any, List, Optional, Sequence, Tuple, Union
Copy link
Member

Choose a reason for hiding this comment

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

Remove all deprecated aliases. We don't use Optional or Union either.

@@ -0,0 +1,170 @@
from __future__ import annotations
__all__ = ["Axes3D", "_Quaternion", "get_test_data"]
Copy link
Member

Choose a reason for hiding this comment

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

Is __all__ actually relevant in type stubs?

@ABarpanda
Copy link
Author

Oh thanks
The comments are really detailed😅
I will make the changes as soon as possible

label_namer="y")
@_docstring.interpd
def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
def scatter(self, x, y, z=0, s=None, c=None, marker=None, cmap=None, norm=None,
Copy link
Member

Choose a reason for hiding this comment

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

You can't change the signature of Axes methods. Please revert.

@ABarpanda
Copy link
Author

@timhoffm Please check the latest commit...

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

@ABarpanda please be more carefully to fully implement requested changes and also fix the reported linting / typing errors before requesting a new review.

Comment on lines +5080 to +5083
zs : float or array-like, default: 0
The z-positions. Either an array of the same length as *xs* and
*ys* or a single value to place all points in the same plane.
Copy link
Member

Choose a reason for hiding this comment

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

Please revert as well.

self,
x: float | ArrayLike,
y: float | ArrayLike,
z: float | ArrayLike,
Copy link
Member

Choose a reason for hiding this comment

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

Please revert as well.

title: Text
_axis_map: dict[str, Axis]
_projection_init: Any
_axis_names: tuple[Literal['x'], Literal['y']] | tuple[Literal['x'], Literal['y'], Literal['z']]
Copy link
Member

Choose a reason for hiding this comment

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

@QuLogic not sure. I think right now this is true at least within the core library. At least PolarAxes still has ("x", "y") whether that is desirable is another topic.

fig : Figure
The parent figure.
rect : tuple (left, bottom, width, height), default: (0, 0, 1, 1)
rect : tuple (left, bottom, width, height), default: None
Copy link
Member

Choose a reason for hiding this comment

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

Please revert. Defaults stated in the docstring are the logical defaults, not necessary what's formally given as the default placeholder object.

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.

[MNT]: Inconsistent type annotation

3 participants