Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #945 +/- ##
==========================================
+ Coverage 88.98% 89.05% +0.07%
==========================================
Files 140 140
Lines 13676 13691 +15
==========================================
+ Hits 12169 12193 +24
+ Misses 1507 1498 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…gative values.
This commit enhances the code generator to correctly determine the base
class for enumerations.
* `comtypes/tools/codegenerator/namespaces.py`:
- Introduce `to_enums` method to generate Python `enum` classes.
- If an enumeration contains negative values, it will be generated as
`IntEnum` (e.g., `MsiInstallState`).
- If an enumeration contains only non-negative values, it will be
generated as `IntFlag` (e.g., `OLE_TRISTATE`).
* `comtypes/tools/codegenerator/codegenerator.py`:
- Update the import statement to dynamically import `IntEnum` and `IntFlag`
based on their usage.
- Utilize the new `to_enums` method for enum generation.
* `comtypes/test/test_client.py`:
- Add `test_enum_base_classes` to verify the correct generation of
`IntEnum` and `IntFlag` for enums based on their value ranges.
This addresses issue for Python 3.15+ compatibility where `IntFlag` might
truncate negative values.
Remove the temporary logic that skipped tests on Python 3.15 alpha/beta versions. This logic was previously added to avoid `RuntimeError` during import due to `PyCArgObject` layout changes.
Update `util` to accommodate changes in the internal `PyCArgObject` structure introduced in Python 3.15. The `tag` field was changed from `c_char` to `c_char_p`, and the `size` field was changed from `c_int` to `c_ssize_t`. This change uses a version-based bridge to maintain backward compatibility with older Python versions.
junkmd
force-pushed
the
py315_support
branch
from
September 22, 2026 08:48
c2b7ea7 to
7b9468c
Compare
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.
fixes: #894 #938
1. Summary
This PR adds official support for Python 3.15 to
comtypes.It resolves internal CPython ABI/struct layout incompatibilities and updates the code generator to handle Python 3.15's changes to
enum.IntFlag.Warning
Breaking Change:
Enumerations containing negative member values are now generated as
enum.IntEnuminstead ofenum.IntFlag. This avoids Python 3.15 range-masking behavior and mathematically inconsistent bitflag definitions, but may affect user code performing bitwise operations orIntFlagtype checks on those enums.2. Motivation & Background
Python 3.15
PyCArgObjectLayout Change:PyCArgObjectinctypeschanged (tagchanged fromc_chartoc_char_p, andsizechanged fromc_inttoc_ssize_t).comtypes.utilfail or cause memory access violations on Python 3.15.Python 3.15
enum.IntFlagNegative Member Masking:IntFlagreinterprets negative member values by masking them into the positive bit domain rather than preserving their negative literal values (e.g.,-1).IntFlag, causing negative constants (such asMsiInstallState.msiInstallStateUnknown = -1) to corrupt their literal values on Python 3.15+.3. Breaking Changes & Migration Guide
Description of the Incompatibility
comtypes.gen.<mod>) inherited fromenum.IntFlag.enum.IntEnum.enum.IntFlag.Impact on Your Code
|,&,^,~) on negative-valued enums (e.g.,MsiInstallState) will no longer return an enum instance or may raise aTypeErrordepending on usage.isinstance(val, enum.IntFlag)orissubclass(EnumType, enum.IntFlag)will returnFalsefor enums with negative values.Migration Action
IntEnumvalues using equality==rather than bitwise masking&).enum.IntFlag.4. Key Changes
Core & Code Generator
comtypes.tools.codegenerator.namespaces.EnumerationNamespaces:IntEnum(if negative values exist) orIntFlag.IntEnumand/orIntFlagbased on whether each is used.comtypes.util:PyCArgObjectfields based onsys.version_info >= (3, 15)(_TAG_TYPE = c_char_p,_SIZE_TYPE = c_ssize_t).Tests & Documentation
comtypes.test.test_client: Addedtest_enum_base_classesto assert correct base class assignment (IntEnumvsIntFlag) based on member sign.comtypes.test.test_util: Removed temporary skip logic for Python 3.15 alpha/beta.docs/source/client.rst: Updated documentation with aChanged in version 1.5.0callout detailing theIntEnum/IntFlagdistinction and rationale.CI & Build Infrastructure
.github/workflows/autotest.ymlto include Python 3.15 in the test matrix.5. Verification & Testing
comtypes.clear_cache).PyCArgObjectoffset calculation on Python 3.15.IntEnumfor negative members andIntFlagfor positive members.