Code quality improvements: modernize string formatting and fix linting issues - #971
Merged
Merged
Conversation
Ruff 0.16 greatly expanded its default rule set. Fix the newly surfaced issues (TRY201, TRY203, TRY004, FLY002, LOG001, LOG009, stale noqa directives) and ignore BLE001 (blind except), matching this codebase's existing style of deliberate broad exception handling for defensive fallbacks.
Codecov Report❌ Patch coverage is
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(because pre-commit autoupdate fails and can't fix the various cases)
This PR modernizes the codebase by replacing older string formatting patterns with f-strings, fixes deprecated logging constants, improves exception handling, and addresses various linting issues.
Key Changes
String formatting modernization: Replaced
.join()calls and string concatenation with f-strings in:traitlets/traitlets.py:_resolve_string()methodtraitlets/config/application.py:flatten_flags()methodtraitlets/utils/text.py:_dedent()functionLogging constant updates: Replaced deprecated
logging.WARNwithlogging.WARNINGthroughout:traitlets/config/application.py: UpdatedLevelFormatter.highlevel_limitandlog_leveldefault valuetests/config/test_application.py: Updated test assertionstests/test_typing.py: Updated typing testException handling improvements:
traitlets/traitlets.py: Changed bareraise eto bareraisefor cleaner exception re-raisingtraitlets/config/application.py: ChangedAssertionErrortoTypeErrorfor invalid subcommand mappings (more semantically correct)Type annotation ordering: Normalized union type ordering to follow a consistent pattern (e.g.,
Sentinel | str | Noneinstead ofSentinel | None | str)Linting improvements:
# noqa: E741comments for variable namesl(now using ruff which doesn't flag this)# noqacomments for intentional patterns (e.g.,TRY203forSystemExithandling,LOG001for logger instantiation)# noqa: F405comment from__all__exportpyproject.tomlto ignoreBLE001for defensive exception handlingTooling: Updated ruff pre-commit hook from v0.15.22 to v0.16.1
Implementation Details
The changes maintain backward compatibility while improving code quality and readability. The exception handling change from
raise eto bareraisepreserves the original traceback, which is the Python best practice. Type annotation reordering follows PEP 604 conventions for consistency.