Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: revealed type forFigure.subfigures is not correct #30313

Open
@MarcoGorelli

Description

@MarcoGorelli

Bug summary

The overloads forsubfigures aren't quite correct

The issue is that

defsubfigures(self,nrows=1,ncols=1,squeeze=True,

hassqueeze=True as the default, but the first overload incorrectly notesFalse as the default

@overload
defsubfigures(
self,
nrows:int= ...,
ncols:int= ...,
squeeze:Literal[False]= ...,
wspace:float|None= ...,
hspace:float|None= ...,
width_ratios:ArrayLike|None= ...,
height_ratios:ArrayLike|None= ...,
**kwargs
)->np.ndarray: ...

Code for reproduction

importmatplotlib.pyplotaspltfromtypingimportreveal_typefig=plt.figure(layout='constrained',figsize=(10,4))reveal_type(fig.subfigures(1,2,wspace=0.07))reveal_type(fig.subfigures(1,1,wspace=0.07))reveal_type(fig.subfigures(1,2,wspace=0.07,squeeze=True))reveal_type(fig.subfigures(1,1,wspace=0.07,squeeze=True))

Actual outcome

(running the above with mypy)

t.py:6: note: Revealed type is "numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]]"t.py:7: note: Revealed type is "numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]]"t.py:9: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:10: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"

Note that the reveal types differ, even thoughsqueeze=True is the default

Expected outcome

t.py:6: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:7: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:9: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"t.py:10: note: Revealed type is "Union[numpy.ndarray[builtins.tuple[Any, ...], numpy.dtype[Any]], matplotlib.figure.SubFigure]"

Additional information

No response

Operating system

No response

Matplotlib Version

3.10.3

Matplotlib Backend

No response

Python version

3.12

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp