refactor: Simplify trivial code patterns#3151
Open
ChihweiLHBird wants to merge 4 commits into
Open
Conversation
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Contributor
There was a problem hiding this comment.
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/returnpatterns. - Replace
not x == ywithx != yin WebSocketconnection_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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
Signed-off-by: Zhiwei Liang <zhiwei.liang@zliang.me>
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.
!=instead ofnot x == yin websocketconnection_lostnot exprinstead ofFalse if expr else Truein CLI arg parsingtuple([...])forCancelledErrorsif ...: return True; return FalseinWorkerProcess._add_config