-
-
Notifications
You must be signed in to change notification settings - Fork 104
Closed
Labels
debtenhancementNew feature or requestNew feature or requesttestsenhance or fix testsenhance or fix tests
Milestone
Description
Description / Problem
Currently, the ITEMIDLIST definition in comtypes.shelllink is treated as a simple c_int.
comtypes/comtypes/shelllink.py
Lines 45 to 47 in 844a111
| # fake these... | |
| ITEMIDLIST = c_int | |
| LPITEMIDLIST = LPCITEMIDLIST = POINTER(ITEMIDLIST) |
While this works as an opaque handle in some cases, it presents several issues for robust development:
- Lack of Introspection: Developers cannot access internal fields of
ITEMIDLISTandSHITEMIDwithout manual casting, which is error-prone. - Incomplete Type Hinting: Methods such as
GetIDListandSetIDListusehints.Incomplete, providing no useful information for IDEs or static analysis tools (like mypy). - Potential for Memory Errors: Without a formal structure, managing the memory of PIDLs is less intuitive.
Proposed Changes
-
Formal Type Definitions:
- Define
SHITEMIDandITEMIDLISTas properctypes.Structureclasses. - Ensure
LPITEMIDLISTandLPCITEMIDLISTcorrectly pointer to these structures.
- Define
-
Interface Enhancements:
- Update
IShellLinkAandIShellLinkWvtables to use these formal types. - Replace
hints.Incompletewith_Pointer[ITEMIDLIST]and explicitHRESULTreturns.
- Update
-
Added Test Coverage:
- Introduce unit tests in
test_shelllink.pyto verify round-tripping (Set/Get) ofITEMIDLIST.
- Introduce unit tests in
Benefits
- Better autocompletion and type checking in modern IDEs.
- The library will more accurately reflect the underlying Windows API structure.
- Formal structures reduce the likelihood of pointer arithmetic errors or incorrect memory size assumptions.
Backward Compatibility
This change is expected to be highly backward compatible as LPITEMIDLIST remains a pointer.
Existing code treating it as a handle should continue to function without modification.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
debtenhancementNew feature or requestNew feature or requesttestsenhance or fix testsenhance or fix tests