Skip to content
Merged
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
Prev Previous commit
Next Next commit
Do not enable REDUNDANT_EXPR accidentally.
  • Loading branch information
tyralla committed Jan 10, 2025
commit 9b54ab1635a8a7e6d81ce7d304bf0e2a289a7704
3 changes: 2 additions & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ def accept_loop(
# If necessary, reset the modified options and make up for the postponed error checks:
if warn_unreachable or warn_redundant:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO this if and the two ifs above are only making the logic more obscure. It should be simply: store, set, restore.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I removed the two ifs above (one of them by using set.discard instead of set.remove). However, removing the third if would mean unnecessary calls of self.accept(body) in cases where neither unreachable nor redundant-expr are enabled. But I adjusted the latter according to @hauntsaninja's suggestion, which might look a little clearer.

self.options.warn_unreachable = warn_unreachable
self.options.enabled_error_codes.add(codes.REDUNDANT_EXPR)
if warn_redundant:
self.options.enabled_error_codes.add(codes.REDUNDANT_EXPR)
with self.binder.frame_context(can_skip=True, break_frame=2, continue_frame=1):
self.accept(body)

Expand Down