Repository navigation
Fix Python consumer instance and input typing - #171
Merged
Merged
Conversation
Separate interface instance protocols from wrapper factories, model native Object inputs without widening outputs, and use Self for context-manager covariance. Add strict same-package, independent-package, SDK, and native lifetime regressions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ✅ Passed
|
Update the stale factory expectation shared by test-rust and coverage. Assert matching generated Python implementation and stub input types, native-wrapper unwrapping, and unchanged nullable raw-value outputs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Cover qualified decorators and unchanged nullable Object outputs individually, including the native wrapper's read-only _obj property. Avoid a brittle total that changed with the added input protocol capability. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Use projected input contracts for collection keys and mutation values while preserving raw nullable outputs and existing ABC contracts. Distinguish scalar and slice assignment, and cover PropertySet, generated maps, typed vectors, independent identities, invalid inputs, and native null carriers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bind metaclass from_value to its receiving interface class through the existing TypeVar instead of fixing its return to the base interface. Keep factories outside instance protocols and preserve independent static factory results. Add exact subclass, projector, wrong-input, and native identity regressions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Shawn Yuan (shuaiyuanxx)
approved these changes
Sep 20, 2026
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.
Summary
Fix the Python consumer typing contracts behind four release-audit cases, the related collection-subscript input omission, and subclass-preserving interface factories without changing native dispatch, public runtime APIs, canonical interface identities, or JavaScript output. This is an independent change based on
34eb6246627c671113a501c00edc8e3317fc8b3d; it does not include the JS native-wrapper or GDI/USER32 work.from_valueandIBuffer.from_bytesremain available on the interface class through its stub metaclass._DynWinRTProjectordescribes the already-bound factory method, preserving typedas_interface(...)calls without requiring runtime-class instances to expose an unrelated factory. Inheritedfrom_valueretains the actual receiving subclass instead of returning a fixed base-interface type.Objectinputs a precise native-wrapper protocol (_obj: DynWinRTValue) alongside rawDynWinRTValue. Apply the input contract to methods, setters, arrays, and collection inputs; keep outputs asDynWinRTValue | None. Generated runtime annotation support uses the same protocol definition. Arbitrary Python objects, unboxed strings, invalid_objvalues, unrelated interfaces/classes, and class objects remain rejected. Ordinary Object parameters do not implicitly boxNone; collection dunders retain their existing nullable ABC signatures, not a new runtime conversion.Selffrom generated context managers so baseLikeprotocols accept derived wrappers and preserve the entered type. Closing andLiteral[False]exception behavior are unchanged.PropertySet/IMapsubscript assignment and vector item assignment, slice assignment, andinsert. Read/iteration outputs remain unchanged. Integer assignment takes one item; slice assignment takes an iterable of items.The
Button.contentcontract was already narrow before its consumer rejection became exposed; this fixes that typing mismatch with the existing working marshaling, not a newly changed native setter. NoAny, casts, ignore comments, legacy marker fallbacks, or handwritten generated stubs were added. Affected Python snapshots were regenerated through the existing snapshot update mechanism.Consumer evidence
Generated before/after from the same pinned inputs. The actual sample sources were copied unchanged into isolated generated packages. Every check explicitly includes the generated package with
mypy --strict --no-incremental --follow-imports=normal; no imported-library errors are suppressed.StorageFileintoIStorageFileIRandomAccessStreamTextBlockintoButton.contentContainerVisualintoset_reference_parameterThe original 22-seed closure remains clean after both follow-ups: 2,631 stubs, strict mypy zero errors with both source and installed stubs. The earlier audit also compiled all 2,629 generated Python implementations. Inputs are Windows SDK 10.0.26100.0 (
Windows.winmdSHA25611191cbcc796e520d47547b3f986be94a48556fe336d4e63334596d9f31a7806), WinUI 2.3.0, and InteractiveExperiences 2.1.3, using the same six hash-verified WinMD files as the audit. No SDK restore/download was performed.Collection input follow-up
Commit
17d94036addresses the confirmed existing declaration omission:properties["uri"] = uriandmapping["uri"] = urialready work at runtime, but their stubs reused the narrower read-result type. The shared collection declaration helper now uses a separate input annotation for subscript keys, mutation values, and vector insertion. This covers concrete classes,Likeprotocols, standalone interfaces, and embedded interfaces while preserving the existing nullablecollections.abccontract. Native nulls still useDynWinRTValue.null_value(); no implicitNoneboxing or runtime behavior was added.The actual SDK regression reproduces four rejected
Uriassignments across PropertySet/Like/standalone-map/embedded-map before the fix, then passes strict mypy with source and installed stubs. Additional synthetic consumers cover Object keys, independently generated derived wrappers, vector scalar/slice assignment, insertion, append, exact unchanged read types, and rejected wrong identities/input shapes. The independent PropertySet/IMap native control checks wrapper/raw/null-carrier round trips and requires both its success marker and a successful process exit.A separately reported Python probe that printed its completion marker before exiting with
0xC0000005remains unattributed and paused pending its original script. These declaration-only follow-ups do not change the runtime or claim that the normal controls resolve that report.Subclass factory P2
Commit
5fc91889separately fixes the P2 that was not addressed by17d94036: the metaclassfrom_valuedeclaration returned a fixed interface name. Its signature now binds the existing type variable to the receiving class:from_value(cls: type[_InterfaceT], obj: DynWinRTValue) -> _InterfaceT. Factories remain outside instance Protocols; no descriptor,Any, cast, or new runtime API is needed.The real SDK
IBufferregression reproduces eight errors before this fix and passes after it with both source and installed runtime stubs. It checks base interfaces,TaggedBuffer, a second-level subclass,type[TaggedBuffer]factory variables,_DynWinRTProjector[TaggedBuffer], andas_interface(TaggedBuffer). Six negative cases reject wrong inputs and attempts to treat a base/static-factory result as a subclass.TaggedBuffer.from_bytes(...)intentionally still returnsIBuffer, matching the existing static factory. Native checks verify exact subclass types, inherited members, cached identities, and a successful process exit. All 2,629 generated Python runtime files are byte-identical before/after this P2 fix; only declarations changed.Validation
On native Windows ARM64, Python 3.13.15 and mypy 1.20.2, with this checkout's generator and an offline/locked-built matching wheel installed locally with
--no-index:cargo test -p dynwinrt-codegen --offline --locked --no-fail-fast -- --nocapture --test-threads=2.DYNWINRT_REQUIRE_MYPY,DYNWINRT_REQUIRE_IMPLEMENTATION_RUNTIME,DYNWINRT_REQUIRE_TSC,DYNWINRT_REQUIRE_WIN32_METADATA, andDYNWINRT_TEST_INSTALLED_RUNTIMEwere all enabled. No missing-dependency skip messages. The ignored test is the existing opt-in metadata review-artifact exporter.DYNWINRT_TEST_INSTALLED_RUNTIME=1runs the consumer checks with both source and installed runtime stubs.as_interfacecalls, runtime type-hint resolution, exact context-manager identity, exception propagation, close counts, and rejected invalid Object inputs.audio/wav, 91,566 bytes); no playback.Environment provenance and limits: initial full-suite attempts were blocked by missing local JS build artifacts; that limitation is retained in the original evidence, not confused with the remote assertion failures below. For the complete codegen runs, JS validation dependencies were restored with
npm ci --offline --ignore-scripts, and the 18-file ARM64 production artifact built from34eb624was copied read-only into this worktree's ignoreddist. Every copied file was hash-verified; native binary SHA256 is75d16e0c9facfdd36ab3b9f3a15562940e3e4b9df47bd79ddc97b6166abdcf45. JS/core sources and Cargo manifests/lockfile have no differences from that artifact's source commit. TypeScript is 5.9.3; Win32Metadata is the hash-verified cached 71.0.14-preview input. This is a production artifact, not test-hooks. The complete mixed-language coverage pipeline and full two-language E2E were not run locally; a coverage-profile test run is not a coverage-pipeline success. No local WinUI startup, audio playback, notification/auth flow, or non-ARM64 execution is claimed.CI follow-up
The first two remote CI attempts exposed two missed legacy test assertions; both
test-rustandcoveragestopped on the same assertion in each attempt. They were real test regressions, not the local JS environment limitation:1813cddfupdates the observable-vector factory assertion to check the exact native-wrapper input union in both.pyand.pyi, the existing unwrap operation, and unchanged nullable raw-value outputs.90146b54replaces a brittle total-property-decorator count (2, now3because of_obj) with individual checks of qualified decorators, nullable Object output types, and the non-null native_objcapability. It does not merely increase the count.Those two follow-ups are test-only. No production logic, coverage threshold, exclusion, or negative-input control was weakened. Before/failure and after/pass logs are retained. The subsequent coverage warning about unexecuted JS binding source followed the early Rust-test failure; no coverage rule was changed to mask it. Consult the checks tab for the latest commit's remote result rather than treating local success as remote success.
Migration
Regenerate complete Python packages with this generator and use/reinstall the matching runtime package and stubs. Do not patch individual
.pyifiles. The #167 full-regeneration migration for packages exchanging closed generic protocols remains intact, including canonical markers and the absence of legacy compatibility fallbacks. No consumer casts or runtime API changes are required.