Skip to content

TYP: Clean up CapStyle/FillStyle type hints #25719

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

Merged
merged 2 commits into from
Apr 19, 2023
Merged

Conversation

ksunden
Copy link
Member

@ksunden ksunden commented Apr 18, 2023

PR Summary

Inputs generally accept either the enum or the raw string (literal), outputs are only the string literals

plotnine passes string literals, which are accepted, but did not previously type check

This ensures for instance that obj.set_capstyle(obj.get_capstyle()) type checks, while also not misrepresenting the return type.

Enums are a bit odd, as they do inherit from str (for these cases), and so it kind of works, but we actually return [Cap|Join]Style.name, not the instance itself.
We know this to be a limited set of literals, so type hint it as such.

PR Checklist

Documentation and Tests

  • Has pytest style unit tests (and pytest passes)
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

Inputs generally accept either the enum or the raw string (literal), outputs are only the string literals

plotnine passes string literals, which are accepted, but did not previously type check
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
@oscargus oscargus added this to the v3.8.0 milestone Apr 19, 2023
@oscargus oscargus merged commit 5dca030 into matplotlib:main Apr 19, 2023
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request May 6, 2023
When these Enum classes were added in matplotlib#18544, they were supposed to be
for documentation only. To that end, matplotlib#22055 was a followup that ensured
that only the strings were exposed from the getter side.

However, when user-supplied cap/join style were added in matplotlib#20914, they
were only for the Enum type instead of the string, so correctly allow
strings here as well.

Also, specifically type hint the return values as literals, as was done
in matplotlib#25719.
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request May 6, 2023
When these Enum classes were added in matplotlib#18544, they were supposed to be
for documentation only. To that end, matplotlib#22055 was a followup that ensured
that only the strings were exposed from the getter side.

However, when user-supplied cap/join style were added in matplotlib#20914, they
were only for the Enum type instead of the string, so correctly allow
strings here as well.

Also, specifically type hint the return values as literals, as was done
in matplotlib#25719.
@QuLogic QuLogic mentioned this pull request May 6, 2023
1 task
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request May 31, 2023
When these Enum classes were added in matplotlib#18544, they were supposed to be
for documentation only. To that end, matplotlib#22055 was a followup that ensured
that only the strings were exposed from the getter side.

However, when user-supplied cap/join style were added in matplotlib#20914, they
were only for the Enum type instead of the string, so correctly allow
strings here as well.

Also, specifically type hint the return values as literals, as was done
in matplotlib#25719.
devRD pushed a commit to devRD/matplotlib that referenced this pull request Jun 5, 2023
When these Enum classes were added in matplotlib#18544, they were supposed to be
for documentation only. To that end, matplotlib#22055 was a followup that ensured
that only the strings were exposed from the getter side.

However, when user-supplied cap/join style were added in matplotlib#20914, they
were only for the Enum type instead of the string, so correctly allow
strings here as well.

Also, specifically type hint the return values as literals, as was done
in matplotlib#25719.
melissawm pushed a commit to melissawm/matplotlib that referenced this pull request Jun 15, 2023
When these Enum classes were added in matplotlib#18544, they were supposed to be
for documentation only. To that end, matplotlib#22055 was a followup that ensured
that only the strings were exposed from the getter side.

However, when user-supplied cap/join style were added in matplotlib#20914, they
were only for the Enum type instead of the string, so correctly allow
strings here as well.

Also, specifically type hint the return values as literals, as was done
in matplotlib#25719.
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