Skip to content

TYP: Improve type coverage of matplotlib.text - #32139

Merged
timhoffm merged 1 commit into
matplotlib:mainfrom
Aniketsy:type-text
Jul 31, 2026
Merged

TYP: Improve type coverage of matplotlib.text#32139
timhoffm merged 1 commit into
matplotlib:mainfrom
Aniketsy:type-text

Conversation

@Aniketsy

@Aniketsy Aniketsy commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

PR summary

  • with this we have 100 % type coverage in matplotlib.text
  • As Both text and s get converted to a string, so they can accept any value, but using Any has side effect, that it switches off type checking wherever it's used, to safeguard this replaced with Object (i'd like to know thoughts on this as this part is suggested by ai)

  • just in case for now i'm creating one PR for each file to keep this clean, but if members prefer to merge small changes in one , happy to do that, please let me know .
  • thanks to (https://jorenham.github.io/typestats/dashboard/report/#matplotlib) as it really makes easy to identify missing type coverage and i'll be following that for my further PRs too.

Towards #32157

AI Disclosure

No AI (except suggestion to use object in text)

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • Plotting related features are demonstrated in an example
  • New features and API changes have release notes
  • Documentation complies with general and docstring guidelines

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to object is the right thing to do.

Comment thread lib/matplotlib/text.pyi
parse_math: bool | None = ...,
antialiased: bool | None = ...,
**kwargs
**kwargs: Any

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The supported kwargs are actually known. See the docs https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text

We could be more specific and define them in a TextProperties TypedDict and Unpack[TextProperties] here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timhoffm thanks for the review, this indirectly answerd my question from other PR.

The supported kwargs are actually known. See the docs https://matplotlib.org/stable/api/text_api.html#matplotlib.text.Text

We could be more specific and define them in a TextProperties TypedDict and Unpack[TextProperties] here.

make sense, i'll update with this and my other PRs too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this separately, because it's a dedicated and complex enough effort: Basically what we want is a Typed Dict for the artist properties. Artist properties are essentially the things you can set_[propname] on any object. These are in many cases the accepted and passed though by kwargs, and therefore artist property Typed Dicts make sense.

You'll want to create a Typed Dict hierarchy following the Artist hierarchy, i.e. TextProperties inheriting from ArtistProperties.

I'll merge this PR as, and you can do a follow-up with the typed dicts.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this separately, because it's a dedicated and complex enough effort: Basically what we want is a Typed Dict for the artist properties. Artist properties are essentially the things you can set_[propname] on any object. These are in many cases the accepted and passed though by kwargs, and therefore artist property Typed Dicts make sense.

thanks for explanation, make sense.

Would it be fine if I open one issue for type annotation, which basically keep track, and maybe i can ask or discuss, any point there.

I'll merge this PR as, and you can do a follow-up with the typed dicts.

also, thanks for merging this, i've two more opened PR, those are also simple with small changes, please have a look when you get chance and share your thoughts.

@timhoffm
timhoffm merged commit c7f1d3a into matplotlib:main Jul 31, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants