Skip to content

Improve Python projection ergonomics and add WinRT samples - #107

Merged
leileizhang (lei9444) merged 17 commits into
mainfrom
feature/python-samples-and-project-as
Aug 27, 2026
Merged

leileizhang (lei9444) merged 17 commits into
mainfrom
feature/python-samples-and-project-as

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Improve Python projection ergonomics end to end: add safe project_as, normalize WinMD overloads, make RuntimeClass/interface typing sound, and provide nine runnable WinRT/Windows App SDK samples.

Projection and typing

  • add dynwinrt.project_as(value, Type) for non-consuming projection of raw Object/IInspectable values or existing wrappers
  • QueryInterface the target IID before projecting a generated interface; incompatible targets fail with OSError
  • preserve projected identity caching and active lifetime-scope tracking
  • keep raw RuntimeClass projection exclusively in project_as(raw, RuntimeClass); use wrapper.as_interface(Interface) or Interface.from_value(raw) for interface views
  • model runtime-class and interface compatibility with unique type-only identity markers, preventing unrelated generated classes from matching empty marker protocols
  • keep concrete return types and collection ABCs
  • do not advertise inherited interface members that the runtime wrapper does not implement; explicit base-interface conversion uses as_interface()
  • declare non-suppressing context managers as Literal[False]

Generated API ergonomics

  • normalize metadata overload names such as *Overload*, *WithOptions, and numeric suffixes when a canonical base method exists
  • preserve exact legacy aliases for compatibility
  • keep overloaded private method names unique across interfaces sharing a vtable slot
  • preserve token-based on_*/off_*, idempotent subscribe_*, and reentrancy-safe once_* event APIs
  • defer async event iterators until JS and Python share apartment-safe event argument marshaling

Python samples

  • async-file-io
  • ocr-image
  • app-lifecycle-single-instance
  • cryptography
  • device-watcher
  • text-to-speech
  • app-notification
  • winui-hello-world
  • custom-winmd-codegen

The samples include generation/run scripts, prerequisites, cleanup guidance, and deterministic validation paths. File I/O, OCR, TTS, and WinUI use explicit or structurally proven interface conversions. Windows App SDK samples accept exact major/minor version arguments. AppNotification guarantees registration cleanup, and custom OCR images no longer assume the built-in test text.

The Python GSMTC sample was removed because a normal python.exe process does not contain the matching fusion-manifest identity required for the restricted globalMediaControl capability. A future sample needs an identity-aware process that actually hosts Python.

Validation

  • cargo test -p dynwinrt-codegen: passed
  • Python binding tests: passed; stubtest: passed
  • full WinAppSDK output: strict mypy passed for 8,732 source files, 8,730 generated modules imported, and compileall passed
  • Python WinRT E2E: 42/42 passed
  • full Python WinUI E2E passed
  • project_as(raw, RuntimeClass) success and interface/int rejection paths validated in runtime and strict mypy
  • AppLifecycle, AppNotification cleanup, WinUI, DeviceWatcher, file I/O, OCR, TTS, cryptography, and custom WinMD samples validated live/smoke

Second review fixes

  • reuse the exact generated private overload helper mapping for factory constructors, including duplicate public-name/vtable-slot cases
  • dispatch RuntimeClass overloads by non-consuming QueryInterface compatibility rather than Python nominal inheritance
  • omit native projection entry points from static-only RuntimeClasses without a verifiable default interface
  • make generated interface from_value() a true classmethod returning the requested subclass
  • stop DeviceWatcher deterministically on timeout before unsubscribing
  • remove the stale root README claim for the deleted Python GSMTC sample

Projection API responsibilities

  • project_as(raw, RuntimeClass) converts raw Object/IInspectable values to generated RuntimeClasses
  • wrapper.as_interface(Interface) queries an interface from an existing wrapper
  • Interface.from_value(raw) queries an interface from a raw DynWinRTValue
  • RuntimeClasses intentionally expose no public from_value(), and project_as() rejects interface classes
  • positive runtime and nominal typing markers restrict project_as() to generated, projectable RuntimeClasses; embedded interfaces carry the same interface marker as standalone interfaces

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 82.32% 78.79% 82.24% regions
Generated Python projections 70.48% n/a 21.71% branches
JavaScript aggregate 18.94% 21.39% 52.74% branches
JavaScript runtime 19.91% 14.28% 7.14% branches
Generated WinRT projections 22.3% 20.11% 52.93% branches
Generated Classic COM projections 13.89% 25.06% 53.56% branches

View workflow run and download full HTML/LCOV/XML reports

leileizhang (lei9444) and others added 3 commits August 25, 2026 16:31
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
@lei9444 leileizhang (lei9444) changed the title Add Python project_as support and WinRT samples Improve Python projection ergonomics and add WinRT samples Aug 25, 2026
leileizhang (lei9444) and others added 13 commits August 25, 2026 22:51
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
@lei9444
leileizhang (lei9444) merged commit fd0c63d into main Aug 27, 2026
26 checks passed
@lei9444
leileizhang (lei9444) deleted the feature/python-samples-and-project-as branch August 27, 2026 07:01
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.

2 participants