Skip to content
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

Improve error messages for except* (B025, B029, B030, B904) #14791 #14815

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ pub(crate) fn duplicate_exceptions(checker: &mut Checker, handlers: &[ExceptHand
}
}

let is_star = checker
.semantic()
.current_statement()
.as_try_stmt()
.is_some_and(|try_stmt| try_stmt.is_star);
if checker.enabled(Rule::DuplicateTryBlockException) {
for (name, exprs) in duplicates {
for expr in exprs {
let is_star = checker
.semantic()
.current_statement()
.as_try_stmt()
.is_some_and(|try_stmt| try_stmt.is_star);
Comment on lines +215 to +219
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for learning purposes. @MichaReiser
Why was this moved inside the diagnostic-branch?

I thought calculating it outside the loop once would be better.

checker.diagnostics.push(Diagnostic::new(
DuplicateTryBlockException {
name: name.segments().join("."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ pub(crate) fn except_with_empty_tuple(checker: &mut Checker, except_handler: &Ex
let Expr::Tuple(ast::ExprTuple { elts, .. }) = type_.as_ref() else {
return;
};
let is_star = checker
.semantic()
.current_statement()
.as_try_stmt()
.is_some_and(|try_stmt| try_stmt.is_star);

if elts.is_empty() {
let is_star = checker
.semantic()
.current_statement()
.as_try_stmt()
.is_some_and(|try_stmt| try_stmt.is_star);
checker.diagnostics.push(Diagnostic::new(
ExceptWithEmptyTuple { is_star },
except_handler.range(),
Expand Down
Loading