Skip to content

[MNT] Use Literal for level parameter in set_loglevel (#30257) #30260

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
wants to merge 3 commits into from

Conversation

nrnavaneet
Copy link
Contributor

Summary

This PR replaces the str type annotation with typing.Literal for the level parameter in matplotlib.set_loglevel. This improves static type checking and IDE autocompletion for common log levels.

Changes

  • Introduced Literal type for accepted log level values: "notset", "debug", "info", "warning", "error", "critical"
  • Helps clarify valid values to users and tooling without changing runtime behavior

Notes

  • No logic has been changed
  • No tests were added since this is strictly a typing improvement

Closes #30257

@timhoffm
Copy link
Member

timhoffm commented Jul 4, 2025

Please apply the same change to pyplot.set_loglevel

@@ -281,7 +283,9 @@ def _ensure_handler():
return handler


def set_loglevel(level):
def set_loglevel(
level: Literal["notset", "debug", "info", "warning", "error", "critical"]
Copy link
Member

Choose a reason for hiding this comment

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

We don't have in-line types anywhere else in the code. I think this belongs in the pyi file. Note that this function is basically obsolete.

Copy link
Member

Choose a reason for hiding this comment

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

This is not solved. Please revert the change here and instead apply it to the .pyi file.

Copy link
Contributor Author

@nrnavaneet nrnavaneet Jul 12, 2025

Choose a reason for hiding this comment

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

Thanks. I'll check into it and fix the issues. There's probably some logical error I'm missing. I'll get back to you with the fixed issue.
Thank you for the advice

@ZPyrolink
Copy link
Contributor

I think create a new TypeAlias in matplotlib.typing can be a good idea. With this, we have the Literal in a single file, and we can use it everywhere is required (matplotlib and pyplot here)

Copy link
Contributor Author

@nrnavaneet nrnavaneet left a comment

Choose a reason for hiding this comment

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

Thank you for the changes

@nrnavaneet
Copy link
Contributor Author

Can u pls help me out with the AppVeyor error?

@QuLogic
Copy link
Member

QuLogic commented Jul 12, 2025

It's probably not important; just fix the other mentioned issues.

Copy link
Contributor Author

@nrnavaneet nrnavaneet left a comment

Choose a reason for hiding this comment

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

Alright

@nrnavaneet
Copy link
Contributor Author

nrnavaneet commented Jul 12, 2025

Hi all 👋,

I’ve decided to move the changes from this PR to a new one: #30302.

As I’m still learning and figuring out best practices, I thought it would be cleaner and easier to manage the fixes in a fresh PR. This way, I can better focus on each part of the original issue (#30257) step by step and avoid confusion from partial commits and merge conflicts.

Thanks so much for your patience and support . I truly appreciate the guidance as I contribute and learn more about the codebase! 🙏

@nrnavaneet nrnavaneet closed this Jul 12, 2025
@nrnavaneet nrnavaneet deleted the fix/use-literal-typing branch July 12, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MNT] [TYPING]: Use of Literal
5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy