-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[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
Conversation
Please apply the same change to pyplot.set_loglevel |
lib/matplotlib/__init__.py
Outdated
@@ -281,7 +283,9 @@ def _ensure_handler(): | |||
return handler | |||
|
|||
|
|||
def set_loglevel(level): | |||
def set_loglevel( | |||
level: Literal["notset", "debug", "info", "warning", "error", "critical"] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
I think create a new TypeAlias in |
There was a problem hiding this 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
Can u pls help me out with the AppVeyor error? |
It's probably not important; just fix the other mentioned issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
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! 🙏 |
Summary
This PR replaces the
str
type annotation withtyping.Literal
for thelevel
parameter inmatplotlib.set_loglevel
. This improves static type checking and IDE autocompletion for common log levels.Changes
Literal
type for accepted log level values:"notset"
,"debug"
,"info"
,"warning"
,"error"
,"critical"
Notes
Closes #30257