Skip to content

refactor: Simplify trivial code patterns#3151

Open
ChihweiLHBird wants to merge 4 commits into
mainfrom
zhiwei/simplify-trivial-patterns
Open

refactor: Simplify trivial code patterns#3151
ChihweiLHBird wants to merge 4 commits into
mainfrom
zhiwei/simplify-trivial-patterns

Conversation

@ChihweiLHBird

Copy link
Copy Markdown
Member
  • Use != instead of not x == y in websocket connection_lost
  • Use not expr instead of False if expr else True in CLI arg parsing
  • Use tuple literals instead of tuple([...]) for CancelledErrors
  • Return boolean expression directly instead of if ...: return True; return False in WorkerProcess._add_config

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors a handful of small boolean/tuple patterns to more direct and idiomatic Python forms across worker process configuration detection, WebSocket lifecycle handling, CLI inspector argument parsing, and compat utilities.

Changes:

  • Return boolean expressions directly instead of multi-branch if/return patterns.
  • Replace not x == y with x != y in WebSocket connection_lost.
  • Simplify tuple construction and boolean negation in compat/CLI code paths.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
sanic/worker/process.py Simplifies _add_config to return the computed boolean expression directly.
sanic/server/websockets/impl.py Uses != for clearer state comparison in connection_lost.
sanic/compat.py Uses a tuple literal for CancelledErrors under the trio path.
sanic/cli/app.py Simplifies inspector flag parsing to not arg.startswith("--no-").

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 87.742%. Comparing base (5ffc7b3) to head (a2554d5).

Files with missing lines Patch % Lines
sanic/server/websockets/impl.py 0.000% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##              main     #3151       +/-   ##
=============================================
- Coverage   87.769%   87.742%   -0.028%     
=============================================
  Files          105       105               
  Lines         8152      8150        -2     
  Branches      1291      1290        -1     
=============================================
- Hits          7155      7151        -4     
- Misses         692       693        +1     
- Partials       305       306        +1     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
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