Skip to content

Code quality improvements: modernize string formatting and fix linting issues - #971

Merged
Carreau merged 1 commit into
mainfrom
claude/ruff-precommit-0-16-1-x1dxr2
Aug 4, 2026
Merged

Code quality improvements: modernize string formatting and fix linting issues#971
Carreau merged 1 commit into
mainfrom
claude/ruff-precommit-0-16-1-x1dxr2

Conversation

@Carreau

@Carreau Carreau commented Aug 4, 2026

Copy link
Copy Markdown
Member

(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() method
    • traitlets/config/application.py: flatten_flags() method
    • traitlets/utils/text.py: _dedent() function
  • Logging constant updates: Replaced deprecated logging.WARN with logging.WARNING throughout:

    • traitlets/config/application.py: Updated LevelFormatter.highlevel_limit and log_level default value
    • tests/config/test_application.py: Updated test assertions
    • tests/test_typing.py: Updated typing test
  • Exception handling improvements:

    • traitlets/traitlets.py: Changed bare raise e to bare raise for cleaner exception re-raising
    • traitlets/config/application.py: Changed AssertionError to TypeError for invalid subcommand mappings (more semantically correct)
  • Type annotation ordering: Normalized union type ordering to follow a consistent pattern (e.g., Sentinel | str | None instead of Sentinel | None | str)

  • Linting improvements:

    • Removed unnecessary # noqa: E741 comments for variable names l (now using ruff which doesn't flag this)
    • Added appropriate # noqa comments for intentional patterns (e.g., TRY203 for SystemExit handling, LOG001 for logger instantiation)
    • Removed redundant # noqa: F405 comment from __all__ export
    • Updated pyproject.toml to ignore BLE001 for defensive exception handling
  • Tooling: 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 e to bare raise preserves the original traceback, which is the Python best practice. Type annotation reordering follows PEP 604 conventions for consistency.

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

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.96%. Comparing base (626bbe5) to head (5eeed47).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
traitlets/config/application.py 75.00% 1 Missing ⚠️
Components Coverage Δ
traitlets 85.30% <88.88%> (-0.06%) ⬇️
tests 99.03% <100.00%> (ø)

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Carreau
Carreau merged commit 8de0a80 into main Aug 4, 2026
33 checks passed
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.

2 participants