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
refactor
  • Loading branch information
tyralla committed Jan 12, 2025
commit f0fac6dbb805217218e546a632c7b661155df0ce
12 changes: 5 additions & 7 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,9 @@ def accept_loop(

# Disable error types that we cannot safely identify in intermediate iteration steps:
warn_unreachable = self.options.warn_unreachable
if warn_unreachable:
self.options.warn_unreachable = False
warn_redundant = codes.REDUNDANT_EXPR in self.options.enabled_error_codes
if warn_redundant:
self.options.enabled_error_codes.remove(codes.REDUNDANT_EXPR)
self.options.warn_unreachable = False
self.options.enabled_error_codes.discard(codes.REDUNDANT_EXPR)

while True:
with self.binder.frame_context(can_skip=True, break_frame=2, continue_frame=1):
Expand All @@ -610,10 +608,10 @@ def accept_loop(
partials_old = partials_new

# If necessary, reset the modified options and make up for the postponed error checks:
self.options.warn_unreachable = warn_unreachable
if warn_redundant:
self.options.enabled_error_codes.add(codes.REDUNDANT_EXPR)
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
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