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.20% +0.21%
==========================================
Files 140 140
Lines 13679 13642 -37
==========================================
- Hits 12172 12169 -3
+ Misses 1507 1473 -34 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
junkmd
force-pushed
the
py315_support
branch
3 times, most recently
from
September 26, 2026 03:17
3563782 to
26bd33b
Compare
junkmd
force-pushed
the
py315_support
branch
3 times, most recently
from
October 4, 2026 09:04
437ea3b to
bd7e5b9
Compare
This was
linked to
issues
Oct 4, 2026
junkmd
force-pushed
the
py315_support
branch
2 times, most recently
from
October 4, 2026 10:49
b9fecb7 to
c9fbbb4
Compare
…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.
…recated` decorator.
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.
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:PyCArgObjectlayout changes incomtypes.util#938.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:IntFlagchanges for negative members. #894.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+.Minor Fixes & Code Cleanups
Alongside the Python 3.15 updates, we have cleaned up several legacy inconsistencies and over-engineered utility functions to improve codebase health and long-term maintainability.
setup_loggingfromlogutil.py. See Proposal: FixNTDebugHandlerand Deprecatesetup_logginginlogutil.py. #920.VARIANT.missingwith a constant. See Replace the integer literal assigned toVARIANT.missingwith a constant. #821.3. Breaking Changes & Migration Guide
enum.IntFlag→enum.IntEnumfor Negative-Valued EnumsDescription 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.Removal of
setup_loggingfromcomtypes.logutilDescription of the Incompatibility
comtypes.logutilprovided asetup_logging(*pathnames)helper that configured the root logger from INI-style config files. It had been deprecated (with aDeprecationWarning) since Proposal: FixNTDebugHandlerand Deprecatesetup_logginginlogutil.py. #920.setup_loggingand the internaldeprecateddecorator have been removed entirely fromcomtypes.logutil. The module now only exposesNTDebugHandler.Impact on Your Code
comtypes.logutil.setup_logging(...)will raiseAttributeErrorat runtime.Migration Action
Set up logging yourself using the standard
loggingmodule. If you were usingsetup_loggingto route debug output to the Windows debug console (e.g., DebugView), configureNTDebugHandlerdirectly:For INI-based configuration, use
logging.config.fileConfigfrom the standard library instead.VARIANT.missingNow Uses Named ConstantDescription of the Change
VARIANT.missingwas initialized by assigning the raw integer literal0x80020004tov._.VT_I4.hresult.DISP_E_PARAMNOTFOUND.Note
There is a subtle nuance here that is easy to overlook.
In Python,
0x80020004is a positive integer (2147549188), whereashresult.DISP_E_PARAMNOTFOUNDis-2147352572(the signed 32-bit interpretation of the same bit pattern). They are not the same Python integer.In practice, however, neither value has caused any observed errors or behavioral differences.
Fundamentally, the semantically significant part of constructing a "missing parameter"
VARIANTis settingvt = VT_ERROR. The exact integer stored inVT_I4plays a secondary role in how COM callee code identifies the argument as missing.This area likely contains a long-standing mistake, and we are taking this opportunity to fix both the literal value and improve readability.
Given the vast ecosystem of COM type libraries, there is a slight possibility this could affect something, but we are proceeding with this change with the clear recognition that this is a bug fix.
No migration action is required.
Important
If you encounter a regression where code that previously worked with
VARIANT.missingnow behaves differently, please report it to the community (open a GitHub issue). Such a regression would most likely surface a pre-existing latent inconsistency that was hidden by the opaque literal, and sharing it will help clarify the correct semantics for future maintainers.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).Logging (
comtypes.logutil)comtypes.logutil:setup_loggingfunction and its associateddeprecateddecorator (see Proposal: FixNTDebugHandlerand Deprecatesetup_logginginlogutil.py. #920).NTDebugHandler.emit(record: logging.LogRecord,writeW: Callable[[str], None], return type-> None).logging.NTDebugHandler = NTDebugHandlerassignment now carries a# type: ignorecomment to suppress mypy's complaint about the monkey-patch.comtypes.test.test_logutil:Test_deprecatedtest class and import ofdeprecated.Automation (
comtypes.automation)VARIANT.missing:0x80020004with the named constanthresult.DISP_E_PARAMNOTFOUNDfor clarity. No behavioral change.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.