Type and project Python delegate callbacks, including MapChanged handlers - #191
Open
leileizhang (lei9444) wants to merge 11 commits into
Open
leileizhang (lei9444) wants to merge 11 commits into
leileizhang (lei9444) wants to merge 11 commits into
Conversation
Collect the delegate callable annotation, event callback adapter, and delegate input conversion in one module so they can be derived from delegate signatures. Generated output is unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Python callables are converted to delegates in one place. The callback annotation and the projection of each native argument now come from the delegate's Invoke signature, with generic arguments substituted, instead of per-name branches for TypedEventHandler, EventHandler, and VectorChangedEventHandler. The same adapter now applies to instance events, static events, callback parameters, and delegate-typed properties through _dynwinrt_delegate(value, iid, types, project); an existing DynWinRTValue delegate still passes through unchanged. Callback arguments are annotated non-null except WinRT Object and IReference<T>, through a single py_delegate_argument_type hook. Modules import the types named by those annotations from the delegate signatures, which replaces the IObservableVector-specific import blocks. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Like IObservableVector<T> over IVector<T>, the Python IObservableMap<K, V> wrapper now extends the IMap<K, V> projection, keeps its own interface for event registration, and its stub is a MutableMapping. MapChanged handlers therefore receive a sender that supports len(), indexing, membership, and iteration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add Python E2E checks that PropertySet and StringMap map_changed handlers receive the observable map and IMapChangedEventArgs for inserts, updates, and removals, and that ThreadPool.run_async and ThreadPoolTimer.create_timer handlers receive projected IAsyncAction and ThreadPoolTimer arguments. Strict mypy consumers cover the handler annotations. The async cancellation E2E now passes an explicit native delegate, which still receives raw arguments, so its work item can poll IAsyncInfo.Status. Document the projected callback arguments. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ✅ Passed
|
Route on_ and subscribe_ through the shared delegate-input helper so DynWinRtDelegate objects, DynWinRTValue delegate values, and wrappers with _obj register unchanged. once_ remains callable-only and raises a clear TypeError for native delegates. Use positional names for internal projection lambdas to prevent collisions after Python name normalization, and keep async-operation callback arguments raw so projection cannot take over their completion. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Include delegate Invoke parameters when collecting structs and other callback annotation dependencies for runtime-class modules, including static and factory interfaces. Add missing runtime-class IID constants for caller-filled arrays. The synthetic struct-event regression generates a class module and executes its extracted adapter, and callback integration checks cover events, static events, callback parameters, setters, async ownership, and colliding metadata names. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Exercise native delegate objects and values through on_, subscribe_, static events, and ThreadPool callbacks, and verify once_ rejects native delegates clearly. Document optimistic callback nullability and the raw async-operation exception. Add a generated Python analyzer that checks compilation, global name resolution in every scope, relative imports, lazy symbols, facades, and stubs. Run it in Python E2E; corpus validation covers all 328 Windows namespaces. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Verify one thousand projected MapChanged deliveries do not grow the active projected lifetime scope and that a retained sender/event argument stays valid after the scope closes. Document ownership and deterministic release. Run async cancellation through the generated ThreadPool.run_async callable path, keeping its IAsyncAction raw and inspecting cancellation through generated IAsyncInfo as documented. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Treat DynWinRtDelegate as a valid delegate input in constructor and overload guards. Constructor stubs intentionally omit raw DynWinRTValue delegate inputs because the single-value native-wrapper shortcut claims them before constructor dispatch. Execute generated constructor and overload dispatch with native delegate objects, and cover additional generated Gamepad value/event paths to preserve Python coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
Problem
MapChangedhandlers were typed asCallable[..., object], and received rawDynWinRTValuearguments that did not exposecollection_changeorkey.Key changes
Invokesignature, with generic arguments substituted.IObservableMap<K,V>overIMap<K,V>so MapChanged senders implement Python's mutable-mapping protocol.DynWinRtDelegate,DynWinRTValue, and wrappers with_objthrough unchanged onon_*,subscribe_*, static events, and callback parameters; reject them clearly fromonce_*.Notes
DynWinRTValuearguments.ObjectandIReference<T>; WinMD has no nullability metadata and runtime nulls still becomeNone.