Repository navigation
refactor: no functions or classes inside functions in app/ - #387
Merged
Merged
Conversation
The Kafka handlers are module-level functions that each router factory registers by calling the subscriber decorator, and the exception handlers are module-level functions registered the same way. The ASGI send and receive wrappers in the cache, metrics, rate limit, security headers and request size middlewares are small classes that hold one request's state. The memory and CPU gauges are module-level callbacks, and the process gauge is a class that keeps its psutil.Process, since cpu_percent measures from the last call. The notification and replay retry loggers are methods that read the notification or the replay config from the retried call's arguments, and the replay dispatch is a method. System notifications go out 20 users at a time through itertools.batched instead of a semaphore inside a closure. The user overview counts statuses with a generator, and the rate limit filters compare precomputed sets instead of lambdas. AGENTS.md states the rule and shows the handler pattern.
HardMax71
enabled auto-merge (squash)
October 13, 2026 23:45
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 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.



app/ defined 33 functions inside other functions. This moves every one of them out, so an AST scan of app/ finds no
deforclassinside a function body.The Kafka handlers in app/events/handlers.py are module-level functions now, each factory registers them with
router.subscriber(...)(handler), and the names say what they do (start_saga,store_completed_result,notify_failed). FastStream wraps each registration separately and Dishka injects through the broker's call decorators, so the same function is safe to register on several routers. The exception handlers moved out ofconfigure_exception_handlersthe same way.The ASGI wrappers in the cache, metrics, rate limit, security headers and request size middlewares are small classes holding one request's
sendorreceive. The metrics one keeps the status and headers its response starts with. The memory and CPU gauge callbacks are module-level functions, and the process gauge is a class that keeps itspsutil.Process, sincecpu_percentmeasures from its last call.The notification and replay retry loggers are methods. They read the notification or the replay config from
RetryCallState.args, the arguments of the retried call, so nothing closes over them, and the replay dispatch is a method too. System notifications go out 20 users at a time withitertools.batchedandgatherinstead of a semaphore in a closure. The user overview counts statuses with a generator, and the rate limit filters compare three precomputed sets instead of three lambdas. Three sort-key lambdas are left, since the issue coversdefandclass.AGENTS.md now states the rule and shows the module-level handler, and the topic architecture doc shows the same pattern.
ruff, mypy, grimp, 569 unit tests and the Grafana contract tests pass, and the docs build in strict mode. The backend e2e suite gave 488 passed, 1 skipped on a fresh local stack with k3s and the worker running this branch, the same count as main.
Closes #383
Summary by cubic
Moves every
defandclassdefined inside a function out to module level inapp/, so an AST scan ofapp/finds no nested functions or classes.itertools.batchedandgatherinstead of a semaphore in a closure.AGENTS.mdand the Kafka topic architecture doc now document the rule and show the pattern.Closes #383.
Written for commit b5b64c3. Summary will update on new commits.