-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use qualified name when checking for overgeneral exceptions #7497
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
Pull Request Test Coverage Report for Build 3455059518
π - Coveralls |
This comment has been minimized.
This comment has been minimized.
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.
Look good thank you ! I think this is a breaking change that we need to put in 3.0 though
It keeps compatibility with the old way (names without dots are handled as they've been before and names with dots weren't supported in any way before) so I think it should be fine? The long-term goal is to remove the old way in 3.0 though. The problem I've run into is that I don't really know how I should make pylint actually show the deprecation warning to the user ( |
This comment has been minimized.
This comment has been minimized.
Is this still a draft @jack1142 ? |
I was waiting for a resolution of the warning discussion before committing any changes. Should be ready for review now. |
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.
Looks pretty refined already, good job !
"broad-except", | ||
args=exception.name, | ||
node=handler.type, | ||
confidence=INFERENCE, |
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 comment has been minimized.
This comment has been minimized.
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.
LGTM π
Shit.. This needs a rebase due to the conflicts. I'm sorry about that @jack1142. I've been very busy. I promise that if you rebase this PR and tag me I'll make sure to merge it immediately after and not let this slip π |
Damn, conflict with 4 files π I will do it tomorrow as I'm a bit busy tonight, thanks for letting me know! |
Yeah this is our bad probably. I have recently started a new job and have had less time for OS. This has messed a bit with out review/merge flow I think. Like I said, make sure to ping my directly as I'll be more likely to see and follow up on it π |
Probably due to #7709, you're going to have to rename old broad-except and consider the new check too, sorry for letting this go stale. |
Co-authored-by: DaniΓ«l van Noord <13665637+DanielNoord@users.noreply.github.com>
We could add few more try except blocks which ensure that message isn't reported I suppose. |
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.
You're right, sorry for the noise !
Head branch was pushed to by a user without write access
This comment has been minimized.
This comment has been minimized.
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.
I'm concerned about the changes shown in the primer. Most of the patterns there look benign, where a broad exception is caught, and then some logging/cleanup is done, and then the original error is re-raised. I didn't think we had consensus on changing that (or at least, I don't see any discussion in the issue.) I think the status quo should be preserved where directly raising MyBroadException
emits a message, but catching and reraising it doesn't.
Yeah, there was definitely no consensus on this change. The primer workflow didn't manage to run successfully on this PR 3 days ago when I added inference to broad-exception-raised so I wasn't really aware of these cases.
I agree, I've done some changes that should hopefully address this. |
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 for the quick updates! (And sorry the primer was down.)
This comment has been minimized.
This comment has been minimized.
All good, I'm happy you/primer caught it before this PR was merged :) |
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 a lot @jack1142, especially for revisiting and fixing the conflicts after we forgot to merge this.
Much appreciated!
b480242
π€ According to the primer, this change has no effect on the checked open source code. π€π This comment was generated for commit b480242 |
@DanielNoord please cleanup the commit message when squashing, it does not have to be super fancy and a perefect synthesis but this one was just a mess π
|
Shit, I thought I did. Sorry about that! |
warnings.warn_explicit( | ||
"Specifying exception names in the overgeneral-exceptions option" | ||
" without module name is deprecated and support for it" | ||
" will be removed in pylint 3.0." | ||
f" Use fully qualified name (maybe 'builtins.{exc_name}' ?) instead.", | ||
category=UserWarning, | ||
filename="pylint: Command line or configuration file", | ||
lineno=1, | ||
module="pylint", | ||
) |
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.
With --jobs 2
, the open()
call is executed for each opened file. E.g. for HomeAssistant I got over 16.000 warnings just for 3 old config values. That should be fixed before we release 2.16
.
https://github.com/cdce8p/ha-core/actions/runs/3470026809/jobs/5797737991#step:8:25
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.BaseException' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.Exception' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.HomeAssistantError' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.BaseException' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.Exception' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.HomeAssistantError' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.BaseException' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.Exception' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.HomeAssistantError' ?) instead.
pylint: Command line or configuration file:1: UserWarning: Specifying exception names in the overgeneral-exceptions option without module name is deprecated and support for it will be removed in pylint 3.0. Use fully qualified name (maybe 'builtins.BaseException' ?) instead.
...
Type of Changes
Description
Allow specifying non-builtin exceptions in overgeneral-exception option using exception's qualified name.
Additionally, tries to deprecate specifying built-in exception names without dots. Small problem - I don't know how to tell pylint to warn about deprecation as
warnings.warn(...)
does not seem to be a valid way to do that.Closes #7495