Add type hints for matplotlib.dates module
PR Summary
This pull request introduces comprehensive type hint stubs (.pyi files) for the matplotlib.dates module.
Why this change is necessary:
By providing explicit type information, this enhancement significantly improves static type checking capabilities for matplotlib.dates. Developers using tools like MyPy, Pyright, or Ruff can now catch potential type-related errors earlier in the development cycle, leading to more robust and maintainable code.
Problem solved:
This PR addresses the current lack of precise type information for matplotlib.dates classes and functions during static analysis. It makes the module's API more explicit and easier for automated type-checking tools to understand and validate.
Implementation reasoning:
The implementation involves adding .pyi files that define the types for the core classes and functions within matplotlib.dates.py. This change directly contributes to Matplotlib's ongoing initiative to expand and improve type hinting coverage across its codebase, fostering better developer experience and code quality.
Closes #29994
PR Checklist
- [x] "closes #29994" is in the body of the PR description to link the related issue
- [x] new and changed code is tested
-
Note: For type stub additions, "tested" typically means running
mypyor similar type checkers to ensure no errors are introduced.
-
Note: For type stub additions, "tested" typically means running
Test Result
mypy, ruff and Pyright with the new dates.pyi
Thanks for the review @QuLogic.
I've only done up to the formatters; please correct the default values in the rest.
Please handle the rest of these.
Done thanks again !!
Learning to write .pyi files. 😅
👋 @bandpooja I accidentally started work on this too at https://github.com/matplotlib/matplotlib/pull/30385 - are you still interested in finishing off this pull request? If you are, please let us know if you have any questions or can help at all. If not, it would be good to know and we can finish off the work you started :)