8000 [Bug]: Type annotation for `add_subplots` has incorrect return type for `projection="3d"` · Issue #29334 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

8000
Skip to content
[Bug]: Type annotation for add_subplots has incorrect return type for projection="3d" #29334
Closed
@stefanv

Description

@stefanv

Bug summary

The return type for add_subplots with projection="3d" should be Axes3D.

The current implementation is:

    @overload
    def add_subplot(
        self, nrows: int, ncols: int, index: int | tuple[int, int], **kwargs
    ) -> Axes: ...
    @overload
    def add_subplot(self, pos: int, **kwargs) -> Axes: ...
    @overload
    def add_subplot(self, ax: Axes, **kwargs) -> Axes: ...
    @overload
    def add_subplot(self, ax: SubplotSpec, **kwargs) -> Axes: ...
    @overload
    def add_subplot(self, **kwargs) -> Axes: ...
    @overload
    def subplots(

Code for reproduction

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
ax: Axes3D = plt.figure().add_subplot(projection="3d")

Actual outcome

Pyright complains:

error: Type "Axes" is not assignable to declared type "Axes3D"
    "Axes" is not assignable to "Axes3D" (reportAssignmentType)

Expected outcome

No error.

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.0

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0