Skip to content

Fix Python codegen typing, imports, and package layout - #106

Open
leileizhang (lei9444) wants to merge 2 commits into
mainfrom
fix/python-winappsdk-codegen-quality
Open

Fix Python codegen typing, imports, and package layout#106
leileizhang (lei9444) wants to merge 2 commits into
mainfrom
fix/python-winappsdk-codegen-quality

Conversation

@lei9444

@lei9444 leileizhang (lei9444) commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Improve the correctness, typing, package layout, and performance of generated Python WinRT bindings.

Changes

  • preserve static factory typing for non-constructible runtime classes while continuing to reject direct construction
  • generate namespace-qualified imports consistently across full and incremental generation
  • emit one canonical Python module and class per WinRT struct
  • fail closed when one consumer would bind different namespace-qualified structs to the same short ABI helper symbols
  • extract shared runtime and typing support into _runtime.py and _typing.pyi
  • make root and namespace exports lazy and resolve root types through their public facades
  • keep ABI helpers available from type-specific facades without exposing them from root or namespace indexes
  • fix observable-vector imports, duplicate declarations, and MutableSequence override annotations
  • propagate XML documentation to public runtime overloads and .pyi declarations
  • generate all selected namespaces through one dependency-resolution and output pass

Validation

  • cargo test -p dynwinrt-codegen: 482 passed
  • Python binding tests: 125 passed
  • Python E2E: 42/42 passed
  • TypeScript E2E: 38/38 passed
  • Python WinUI E2E: python-winui-ok
  • generated Python line coverage: 70.53% (70% gate)
  • full Microsoft.WindowsAppSDK 2.3.1 package: 8,093/8,093 modules import
  • full generated package and consumer sample pass mypy --strict (8,095 source files)
  • root-only imports expose stable public __module__ paths
  • clean wheel install validated constructors, structs, collections, asyncio, AppLifecycle, AppNotifications, and WinAppSDK bootstrap

Full-package generation reduced generated source from 119.67 MB to approximately 109.7 MB and the wheel from 22.70 MB to approximately 20.2 MB. Canonical struct generation reduced 3,105 duplicate definitions to 61, and lazy namespace exports removed the previous eager import of the complete namespace graph.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
@lei9444 leileizhang (lei9444) changed the title Prepare generated Python bindings for first preview Improve Python WinRT code generation Aug 21, 2026
@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

Mixed-language test coverage

Workflow status: ✅ Passed

Layer Lines Functions Branches/regions
Rust, including native .pyd/.node 82.14% 78.62% 82.06% regions
Generated Python projections 70.4% n/a 22.82% 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

@lei9444 leileizhang (lei9444) changed the title Improve Python WinRT code generation Fix Python codegen typing, imports, and package layout Aug 21, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 565c4300-9e07-40c2-8ad3-875138379a86
@lei9444

Copy link
Copy Markdown
Contributor Author

Addressed the review blockers in 23f1e05:

  • Struct symbol collision: Python generation now fails closed when a consumer or canonical struct module would bind distinct namespace-qualified structs to the same short class/ABI-helper symbols. The regression is wired through the generation entry point.
  • Root-only type identity: root lazy exports now load public facades, so __module__ is deterministic for root-only imports.
  • Struct facade helpers: type-specific .py/.pyi facades export the struct class, *_TYPE, pack_*, and unpack_*; root and namespace indexes remain type-only.
  • Coverage: the helper matrix now tests shared _runtime.py once instead of importing every uncalled API module, while retaining local IReference coverage and adding real Point/Rect/Size plus scalar struct helper roundtrips. Local coverage with the CI rcfile is 70.53% against the 70% gate.

Revalidated: codegen 482 passed, Python binding tests 125 passed, Python E2E 42/42, TypeScript E2E 38/38, WinUI E2E python-winui-ok, full strict mypy, and 8,093/8,093 full-package imports.

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