refactor(pyamber): flatten over-nested util packages#4952
Merged
Yicong-Huang merged 3 commits intoapache:mainfrom May 6, 2026
Merged
refactor(pyamber): flatten over-nested util packages#4952Yicong-Huang merged 3 commits intoapache:mainfrom
Yicong-Huang merged 3 commits intoapache:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4952 +/- ##
============================================
- Coverage 42.58% 42.58% -0.01%
+ Complexity 2184 2183 -1
============================================
Files 1031 1005 -26
Lines 38110 37436 -674
Branches 4004 3918 -86
============================================
- Hits 16231 15941 -290
+ Misses 20863 20527 -336
+ Partials 1016 968 -48
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
aglinxinyuan
approved these changes
May 5, 2026
Contributor
Author
|
I need to add more tests. will do it later. |
Several `core/util/<X>/<X>.py` directories existed only to host a single file — a Java/Scala "one class per directory" convention transplanted into Python where it adds noise without value. Two related anti-patterns existed alongside it: - `core/util/expression_evaluator/__init__.py` was 211 lines of evaluator implementation (the package had no other modules). - `core/util/virtual_identity/__init__.py` was 99 lines of helper functions. `__init__.py` should re-export, not host the implementation. Changes: - Flatten single-file directories to flat modules: `runnable/runnable.py`, `thread/atomic.py`, `protocol/base_protocols.py` → `runnable.py`, `atomic.py`, `base_protocols.py`. - Delete `core/util/operator/` — `__init__.py` was a 16-line license header with no exports and no importers. - Move `expression_evaluator/__init__.py` and `virtual_identity/__init__.py` implementations into flat single-file modules (the dirs only ever held the impl + the test file). - Move tests up alongside the new flat modules. - Replace the hardcoded `core.util.expression_evaluator.test_expression_evaluator` module path inside `test_evaluate_object_expression` with `A.__module__` so the test tracks whatever import path it resolves to (it would have broken on this rename otherwise). - Inside `core/util/stoppable/stoppable_queue_blocking_thread.py`, switch the intra-package `from core.util.stoppable import Stoppable` back to the relative `from .stoppable import Stoppable` to avoid hitting the parent package's __init__ mid-initialization. Closes apache#4951
… drain The util-flatten rename touched `core/python_worker.py`'s import lines, and codecov flagged them because the file had no test coverage at all. Add a focused unit test that stubs `NetworkReceiver`, `NetworkSender`, `MainLoop`, and `Heartbeat`, then exercises: - construction wires the receiver's proxy port into the sender, and the receiver's shutdown callback is bound to `worker.stop` - `stop()` cascades to main loop, sender, and heartbeat - `run()` sets the heartbeat stop event after main loop returns Brings `core/python_worker.py` to 100% line coverage.
25eda94 to
ded8661
Compare
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.
What changes were proposed in this PR?
Flatten
core/util/<X>/<X>.pysingle-file directories — the "one class per directory" pattern that was transplanted from Java/Scala — into flat modules undercore/util/. Also extract the implementations that were living directly inside__init__.py(expression_evaluator,virtual_identity) into named modules.Any related issues, documentation, discussions?
Closes #4951.
How was this PR tested?
pytest core/util(60 passed, 1 xfailed) andpytest core/runnables(34 passed) green locally.Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7 (Claude Code)