Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Bad type hint in _AxesBase.twinx() #28624

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

Closed
randolf-scholz opened this issue Jul 29, 2024 · 2 comments · Fixed by #28625
Closed

[Bug]: Bad type hint in _AxesBase.twinx() #28624

randolf-scholz opened this issue Jul 29, 2024 · 2 comments · Fixed by #28625
Milestone

Comments

@randolf-scholz
Copy link
Contributor

randolf-scholz commented Jul 29, 2024

Bug summary

Incorrect type annotation for _AxesBase.twinx() (should be Self, not _AxesBase).

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

# First create some toy data:
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x**2)
z = np.cos(x**2)

# Create four polar Axes and access them through the returned array
fig, axsA = plt.subplots()
axsA.plot(x, y)
axsB = axsA.twinx()
axsB.plot(x, z)  # <-- Cannot access attribute "plot" for class "_AxesBase"

Actual outcome

axsB is of type _AxesBase

Expected outcome

The type of axsB should be the same as the type of axsA.

Matplotlib Version

3.9.1

@randolf-scholz
Copy link
Contributor Author

Potentially fixing this requires adding typing_extensions as a dependency, since typing.Self is not available in 3.10.
Otherwise, users might not have it in their virtual environment when installing matplotlib, leaving the stubs broken.

@randolf-scholz
Copy link
Contributor Author

I made a provisional PR #28625, maintainers likely want to discuss first whether to add the extra dependency. Although imo typing_extensions is kind of must-have if you want to type the library as it is the official place for backporting new typing features.

@QuLogic QuLogic added this to the v3.9.2 milestone Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants