Skip to content

fix: replace bare except with except Exception (E722)#5657

Open
harshadkhetpal wants to merge 1 commit intoaws:masterfrom
harshadkhetpal:fix/bare-except-sagemaker-train
Open

fix: replace bare except with except Exception (E722)#5657
harshadkhetpal wants to merge 1 commit intoaws:masterfrom
harshadkhetpal:fix/bare-except-sagemaker-train

Conversation

@harshadkhetpal
Copy link

Summary

Replace bare except: clauses with explicit except Exception: in sagemaker-train utilities.

Why: Bare except: catches all exceptions including SystemExit, KeyboardInterrupt, and GeneratorExit (PEP 8 E722). Since these catch blocks are used for graceful fallbacks (not re-raising), except Exception: is the correct form — it avoids silently swallowing system-level signals.

Change:

# Before
except:
    pass

# After
except Exception:
    pass

Files Changed

  • sagemaker-train/src/sagemaker/train/evaluate/execution.py (2 instances)
  • sagemaker-train/src/sagemaker/train/common_utils/finetune_utils.py (1 instance)

Testing

No behavior change for normal exceptions — except Exception: catches all standard exceptions. The only difference is that KeyboardInterrupt, SystemExit, and GeneratorExit will now correctly propagate, which is the intended Python behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant