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

Skip to content

[Bug]: Incorrect type stub for ErrorbarContainer's lines attribute. #28467

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
pavyamsiri opened this issue Jun 26, 2024 · 0 comments · Fixed by #28474
Closed

[Bug]: Incorrect type stub for ErrorbarContainer's lines attribute. #28467

pavyamsiri opened this issue Jun 26, 2024 · 0 comments · Fixed by #28474
Milestone

Comments

@pavyamsiri
Copy link

pavyamsiri commented Jun 26, 2024

Bug summary

The type stub for ErrorbarContainer in lib/matplotlib/container.pyi is incorrect.

image

It is also inconsistent with the online documentation.

image

Code for reproduction

from matplotlib import pyplot as plt


fig = plt.figure()
axis = fig.add_subplot(111)

container = axis.errorbar([0, 1, 2], [-0.5, 0.2, 0.3], yerr=[0.01, 0.02, 0.01])
print(container.lines)
for idx, elem in enumerate(container.lines):
    print(f"Element {idx}: {elem} | Type = {type(elem)}")

plt.show()
plt.close()

Actual outcome

image

Expected outcome

Assuming the type stub is correct:

  1. The first element should be a Line2D which is correct
  2. The second element should be a Line2D which is incorrect as it is actually an empty tuple
  3. The third element should be a LineCollection which is incorrect as it is a tuple containing a single LineCollection.

Additional information

I'm not sure if the type stub was always incorrect or it became incorrect over time however it should be fixed as it causes spurious type checker errors.

Obviously we would need to fix the type stub annotation however I am unsure about the true types as it seems that the return types are dynamic dependent on the input arguments to plt.errorbar.

Operating system

Debian

Matplotlib Version

3.8.4

Matplotlib Backend

QtAgg

Python version

3.12.4

Jupyter version

Not applicable

Installation

conda

@QuLogic QuLogic added this to the v3.9.1 milestone Jun 26, 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