Add explicit WinRT Object boxing and type-preserving unboxing to Python - #194
Open
leileizhang (lei9444) wants to merge 2 commits into
Open
leileizhang (lei9444) wants to merge 2 commits into
leileizhang (lei9444) wants to merge 2 commits into
Conversation
Generated Object positions stay native (IInspectable); applications now convert boxed values explicitly at the boundaries that want value semantics. Core: PropertyValueData models every PropertyType that has a payload (37 of 41), unbox_property_value reports payload-less boxes as Unsupported, and box_property_value creates system PropertyValue boxes. JavaScript keeps its exact behavior and messages through a compile-only adapter. Python: - unbox_object additionally supports DateTime, TimeSpan, Point, Size, Rect, their arrays and InspectableArray (elements unboxed by the same rules); already-supported types return the same values, and payload-less boxes still raise OSError. - unbox_object(raw, preserve_type=True) returns dynwinrt.values tags and typed arrays, so to_winrt_object restores the exact PropertyType and value. - to_winrt_object(value, property_type=None) boxes only unambiguous values: a plain int is Int32 only, lists must be homogeneous, and enum members, empty or mixed lists and InspectableArray need an explicit type. - The tags, typed arrays, Point/Size/Rect and PropertyType live in the new dynwinrt.values submodule, outside the top-level namespace. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Python-only checks on generated bindings: - object_value_roundtrip: every PropertyValue.create_* factory (37 PropertyTypes) round-trips through unbox_object(preserve_type=True) and to_winrt_object with its exact PropertyType, and dynwinrt.values.PropertyType matches the metadata enum. - object_value_storage_properties: a temporary file's System.Size unboxes as UInt64 in preserve mode and System.DateModified as an aware datetime. - object_value_device_properties: DeviceInformation.properties values unbox as str, bool and UUID, skipping gracefully without devices. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mixed-language test coverageWorkflow status: ✅ Passed
|
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
unbox_object()raised for DateTime, TimeSpan, Point/Size/Rect and InspectableArray boxes, returned UInt32/Int64/Single values as plain numbers that could not be written back with their original type, and Python had no way to box a value except the generatedPropertyValue.create_*factories. Automatic conversion at everyObjectposition (#192) was rejected: anObjectis not always a box, and a Python value does not say which WinRT type it is.Key changes
PropertyValueDatamodels all 37PropertyTypes that have a payload and addsbox_property_value. JavaScript keeps its exact behavior through a compile-only adapter.unbox_object(value, *, preserve_type=False): adds DateTime, TimeSpan, Point/Size/Rect, their arrays, and InspectableArray, whose elements follow the same rules. Withpreserve_type=True, it returns tags and typed arrays that box again as the samePropertyType.to_winrt_object(value, property_type=None): boxes only values whose WinRT type is unambiguous.property_type=picks an exact type, with range checks.dynwinrt.valuessubmodule: tags (UInt8…Char16), typed arrays, immutablePoint/Size/Rect, and aPropertyTypeIntEnum. They are kept out ofdynwinrt.__all__, so they never shadow the generatedWindows.Foundationnames.PropertyValuefactory;PropertyValuefactories,StorageFileproperties andDeviceInformation.properties.Notes
Objectpositions are still rawDynWinRTValues.unbox_objectno longer raises for the newly supported types. Types it already supported return the same values and Python types.Empty,Inspectable,OtherTypeandOtherTypeArrayboxes still raiseOSError.intboxes as Int32 only. Enum members, empty or mixed lists, and InspectableArray values needproperty_type=or a typed array.PropertyTypeand value, but not the original box's COM identity.