mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 21:14:01 +01:00
DisplayMixin in _display.py takes the methods that reach widgets only through self._widgets: apply, _play, _verdict, on_undo, on_quit, drain, refresh, tick and attach_player. Widget construction stays in ui.py on purpose. test_ui.py fakes the toolkit with patch.object(ui, "tk", fake), so moving _build out makes 22 tests error with "module ui does not have the attribute 'tk'". An earlier attempt did that and was reverted rather than touching the tests. Also dropped the four _key_* adapters; each only discarded Tk's event argument before forwarding, so _bind_keys binds lambdas directly now. One thing worth knowing for the next split: ruff's TC001 is NOT suppressed by __all__ the way F401 is. Moving Callbacks to its own module and re-exporting it left a TYPE_CHECKING-only import that lints clean and raises AttributeError at runtime -- cli.py constructs ui.Callbacks. Reverted; it stays defined in ui.py. ui.py 398 -> 242, _display.py 179. 277 tests pass, both files 100% covered. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
41 lines
3.1 KiB
JSON
41 lines
3.1 KiB
JSON
{
|
|
"intent": "Bring python_pkg/wsg_grabber/ui.py under the 250-line file cap by moving the screen-updating and state-transition halves of ReviewWindow into a mixin, while leaving every line that touches tkinter in ui.py.",
|
|
"scope": [
|
|
"python_pkg/wsg_grabber/ui.py",
|
|
"python_pkg/wsg_grabber/_display.py (new)",
|
|
"Non-goal: no behaviour change, no test changes, no change to the ReviewCommand contract"
|
|
],
|
|
"changes": [
|
|
"Added DisplayMixin in _display.py holding apply, _play, _verdict, on_undo, on_quit, drain, refresh, tick and attach_player -- the methods that reach widgets only through self._widgets and never touch the tkinter module itself.",
|
|
"ui.py keeps Callbacks, Widgets, _build, _bind_keys, video_wid, on_keep, on_pass, shutdown and run, and is now `class ReviewWindow(DisplayMixin)`.",
|
|
"Deleted the four _key_* adapters (_key_keep/_key_pass/_key_undo/_key_quit); each only discarded Tk's event argument and forwarded, so _bind_keys now binds lambdas directly. No test referenced them.",
|
|
"ui.py 398 -> 242 lines; _display.py 179."
|
|
],
|
|
"verification": [
|
|
{
|
|
"command": "python3 -m pytest python_pkg/wsg_grabber/tests/ -q --cov=python_pkg.wsg_grabber --cov-report=term-missing",
|
|
"result": "pass",
|
|
"evidence": "277 passed in 15.15s. ui.py 93 stmts / 12 branches 100%; _display.py 76 stmts / 18 branches 100%."
|
|
},
|
|
{
|
|
"command": "PYTHONPATH=. python3 -c \"from python_pkg.wsg_grabber import ui; ui.Callbacks; ui.Widgets\"",
|
|
"result": "pass",
|
|
"evidence": "Both resolve at runtime. This check exists because an intermediate version moved Callbacks to its own module and ruff's TC001 rewrote the re-export into a TYPE_CHECKING-only import, which passes every linter but makes ui.Callbacks raise AttributeError at runtime -- and cli.py constructs it."
|
|
},
|
|
{
|
|
"command": "pre-commit run --files python_pkg/wsg_grabber/ui.py python_pkg/wsg_grabber/_display.py",
|
|
"result": "pass",
|
|
"evidence": "Only the expected 'no staged evidence artifact' failure remained, which this file satisfies. ruff, ruff format, mypy, pylint, bandit and the coverage-gated pytest all pass with no suppression."
|
|
}
|
|
],
|
|
"risks": [
|
|
"Widget construction deliberately stays in ui.py. test_ui.py fakes the toolkit with patch.object(ui, 'tk', fake), so moving _build to another module makes 22 tests error with \"module ui does not have the attribute 'tk'\". An earlier attempt did exactly that and was reverted rather than adapting the tests, which are out of scope.",
|
|
"Unlike F401, ruff's TC001 is NOT suppressed by listing a name in __all__. A cross-module re-export of a type-annotation-only name cannot be kept at runtime that way; define such classes in the module that must expose them.",
|
|
"ReviewWindow now inherits from an ABC whose abstract methods (shutdown) are satisfied by ui.py. Removing shutdown from ui.py would fail at instantiation rather than at lint time."
|
|
],
|
|
"rollback": [
|
|
"git revert the commit; ui.py returns to its 398-line form and _display.py is deleted.",
|
|
"After rollback, run python3 -m pytest python_pkg/wsg_grabber/tests/ -q to confirm 277 tests still pass."
|
|
]
|
|
}
|