8000 [Bug]: Type hinting missing for datetime type in ax.plot and ax.errorbar · Issue #27140 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: Type hinting missing for datetime type in ax.plot and ax.errorbar #27140

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
frankbolton opened this issue Oct 18, 2023 · 1 comment
Closed

Comments

@frankbolton
Copy link

Bug summary

list of datetime passed to ax.plot results in a mypy error. The same error has been seen in ax.errorbar.

Code for reproduction

import matplotlib.pyplot as plt 
from datetime import datetime 

ax = plt.axes()

ax.plot([datetime.now()], [20.6], label="buggy")

Actual outcome

Argument 1 to "plot" of "Axes" has incompatible type "list[datetime]"; expected "Union[float, Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]], str]" [arg-type]

Expected outcome

no mypy errors

Additional information

No response

Operating system

Windows 11

Matplotlib Version

3.8.0

Matplotlib Backend

TkAgg

Python version

Python 3.9.13

Jupyter version

NA

Installation

pip

@ksunden
Copy link
Member
ksunden commented Oct 18, 2023

This is a well known and actually very tricky corner of type hinting matplotlib...

I am going to close this as a duplicate of #25676, where there is a significant amount of conversation on the subject and the reasons we chose to type hint the way we did/ideas for improvements. Feel free to add info there.

The short version is that units (including datetimes) are runtime-configurable dynamic behavior that simply can't be properly checked by static type checkers. (We can certainly do better, but we really will never be able to capture the full gamut of things without some additional info)

Also xref #26942

@ksunden ksunden clos 5B4A ed this as not planned Won't fix, can't repro, duplicate, stale Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0