Repository navigation
Fixed-point number (VT_CY / VT_DECIMAL) marshaling improvements. - #978
Merged
junkmd merged 14 commits intoOct 31, 2026
Merged
Conversation
…duce unit tests for their representation.
…lude unit tests for conversion.
… `tagDEC`. Due to a lack of proper conditional branching in the production code, it is incorrectly treated as a struct that does not support `IRecordInfo`.
…_CY` `VARIANT`s.
…ARIANT` support.
… `Decimal` values.
… `tagDEC`; add comprehensive unit tests for conversion methods.
…rshaling logic for decimal conversion.
In Python versions before 2.4, the `decimal` module was not in the stdlib. So the check `decimal is not None` was needed. Now this check is always True. So we remove this redundant condition. https://github.com/enthought/comtypes/blob/938fbd50d2077c6bd524790a9ed798c3990cdfc0/comtypes/automation.py#L8-L11
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #978 +/- ##
==========================================
+ Coverage 90.05% 90.33% +0.27%
==========================================
Files 143 145 +2
Lines 14152 14567 +415
==========================================
+ Hits 12745 13159 +414
- Misses 1407 1408 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ts for NaN, Infinity, and non-decimal inputs
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.
Motivation
comtypeshas problems with fixed-point numbers (VT_CYandVT_DECIMAL).Current problems:
VT_CYusesc_longlongfor internal storage. This is not correct becauseVT_CYshould usetagCYstructure.Decimalvalues, the code usesint(round(value * 10000))which silently truncates large values and rounds without warning.getcontext().precchanges the result.VT_DECIMALtype._ctype_to_vartypedictionary is missingVT_CYandVT_DECIMALentries.SAFEARRAYdid not supporttagCYortagDECtypes, so fixed-point numbers could not be used in arrays.Summary
This PR fixes the fixed-point number marshaling.
SAFEARRAYnow supportstagDECandtagCY, and preserves the correct type when the internal storage of aVARIANTisVT_CY.Implicit rounding when passing a
Decimalto aVARIANTparameter has been maintained. Keeping this behavior unchanged for now as it fall under Hyrum's Law.Changes
Changed Behavior
v._.VT_CYnow usestagCYstructure instead ofc_longlong. This is an internal change only (accessed viav._.VT_CY)._ctype_to_vartypenow includestagCY: VT_CYandtagDEC: VT_DECIMALmappings.SAFEARRAY(tagCY)andSAFEARRAY(tagDEC)can now be created and unpacked. Unpacking returnsDecimalvalues for easier use.Not Changed
VARIANT.valueproperty setter behavior for Decimal values is unchangedtagDEC.as_decimal()behavior unchangedInternal Changes
v._.VT_CYis now atagCYstructure, notc_longlong. Code accessing this private attribute directly will need to use.int64property._vartype_to_ctypeand_ctype_to_vartypeupdated forVT_CYandVT_DECIMAL.