Skip to content

Follow TYPE_CHECKING imports and __init__ constructors in DeclaredReceiverTyping, and close partial/sync callbacks in threaded_absence - #643

Merged
trissim merged 2 commits into
mainfrom
feat/receiver-typing-and-callback-closure
Nov 28, 2026
Merged

trissim merged 2 commits into
mainfrom
feat/receiver-typing-and-callback-closure

Conversation

@trissim

@trissim trissim commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Two high-leverage capabilities from Toad bench feedback:

  1. DeclaredReceiverTyping (class_index.py, declared_receivers.py):
    • Captures if TYPE_CHECKING: import aliases on CompactModuleClassHeader.type_checking_import_aliases (kept separate from runtime import_aliases) and resolves annotations / type aliases through annotation_aliases_by_module (runtime aliases still win on overlap). Unlocks app_node.py's if TYPE_CHECKING: from toad.app import ToadApp for every subclass (ToadNode, AppScoped).
    • Captures unambiguous self.<attr> = SomeClass(...) assignments in __init__ (CompactIndexedClass.init_attribute_calls, _compact_init_attribute_calls), rejecting attributes that are annotated, reassigned to another expression, or calling a local parameter/variable shadowing a module symbol. Resolved through DeclaredReceiverTyping.called_reference (handling both scanned classes and installed stub classes, failing closed on unannotated functions).
  2. Method-as-value callback closure in threaded_absence (refactors/threaded_absence.py):
    • functools.partial(fn, *args, **kwargs) binding the target parameter (positionally, or by keyword when partial(...) is passed directly as a call argument) extracts and rewrites the bound argument directly in place (Held<Family>(...) / Absent<Family>() / <Family>.from_optional(...)) for both sync and async functions/methods.
    • Sync single-parameter functions/methods passed directly as callback arguments (e.g. push_screen(..., self.picked_bus), AnimationClock(self._schedule_animation), Qt .connect(self._slot)) adapt cleanly at the callback boundary via lambda <p>: <ref>(<Family>.from_optional(<p>)) (or <p>=None when defaulted), while still refusing .disconnect(...)/removal consumers and async def callbacks (where a sync lambda would break inspect.iscoroutinefunction).

Verification

  • Focused tests (tests/test_declared_receivers.py, tests/test_threaded_absence.py, tests/test_receiver_binding.py, tests/test_receiver_field_bindings.py, tests/test_foreign_absence_branch.py) + 72 test_repository_* guards on desktop.

@trissim
trissim merged commit 7cf475e into main Nov 28, 2026
1 of 10 checks passed
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.

1 participant