Relax type hints for xy and xytext in annotate#31428
Relax type hints for xy and xytext in annotate#31428dikshajangra12918-oss wants to merge 2 commits intomatplotlib:mainfrom
Conversation
The current type hints for xy and xytext are too strict (tuple[float, float]) compared to the actual flexibility supported at runtime (example, dates, etc). This change relaxes the type hints to better reflect real usage.
|
⏰ This pull request might be automatically closed in two weeks from now. Thank you for your contribution to Matplotlib and for the effort you have put into this PR. This pull request does not yet meet the quality and clarity standards needed for an effective review. Project maintainers have limited time for code reviews, and our goal is to prioritize well-prepared contributions to keep Matplotlib maintainable. Matplotlib maintainers cannot provide one-to-one guidance on this PR. However, if you ask focused, well-researched questions, a community member may be willing to help. 💬 To increase the chance of a productive review:
As the author, you are responsible for driving this PR, which entails doing necessary background research as well as presenting its context and your thought process. If you are a new contributor, or do not know how to fulfill these requirements, we recommend that you familiarize yourself with Matplotlib's development conventions or engage with the community via our Discourse or one of our meetings before submitting code. If you substantially improve this PR within two weeks, leave a comment and a team member may remove the |
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
|
Thanks for the suggestion! |
|
Please run |
|
Sir, after applying 'tuple[Any, Any]' , I'm seeing multiple test failures. Instead of this, should we use a more constrained union type(e.g., including numeric and converter-supported types)? |
Sir, I’ve been trying to run the "boilerplate.py" file for the past hour, but I’m not able to get a proper working solution. I tried several methods like creating a virtual environment, installing all required dependencies, setting "PYTHONPATH", and reinstalling matplotlib, but I’m still facing errors. It seems that the script requires a proper development build of matplotlib, and I’m unable to set that up correctly on my system. Could you please guide me on what exactly I should do next? |
You will have to get a proper development version built. Please ask questions at discourse.matplotlib.org |
jklymak
left a comment
There was a problem hiding this comment.
Need to get pyplot changes in...
PR SUMMARY
The current type hints for 'xy' and 'xytext' in 'Axes.annotate' are too strict ('tuple[float, float]') compared to the flexibility supported at runtime.
In practice, Matplotlib accepts a wider range of inputs (example, dates, array-like objects, or other coordinate representations). Restricting these parameters to fixed float tuples can lead to incorrect type checking.
This change relaxes the type hints to 'Any' to better reflect the actual behaviour of the API.
WHY IS THIS CHANGE NECESSARY?
The existing type hints do not accurately represent the accepted input types, which can cause confusion for users and issues with static type checkers.
WHAT DOES THIS SOLVE?
It aligns the type hints with real usage, improving developer experience and reducing false type errors.
ADDITIONAL NOTES
This change only updates type hints and does not affect runtime behaviour.