Description / Problem
Currently, the ITEMIDLIST definition in comtypes.shelllink is treated as a simple c_int.
|
# 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
ITEMIDLIST and SHITEMID without manual casting, which is error-prone.
- Incomplete Type Hinting: Methods such as
GetIDList and SetIDList use hints.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
SHITEMID and ITEMIDLIST as proper ctypes.Structure classes.
- Ensure
LPITEMIDLIST and LPCITEMIDLIST correctly pointer to these structures.
-
Interface Enhancements:
- Update
IShellLinkA and IShellLinkW vtables to use these formal types.
- Replace
hints.Incomplete with _Pointer[ITEMIDLIST] and explicit HRESULT returns.
-
Added Test Coverage:
- Introduce unit tests in
test_shelllink.py to verify round-tripping (Set/Get) of ITEMIDLIST.
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.
Description / Problem
Currently, the
ITEMIDLISTdefinition incomtypes.shelllinkis treated as a simplec_int.comtypes/comtypes/shelllink.py
Lines 45 to 47 in 844a111
While this works as an opaque handle in some cases, it presents several issues for robust development:
ITEMIDLISTandSHITEMIDwithout manual casting, which is error-prone.GetIDListandSetIDListusehints.Incomplete, providing no useful information for IDEs or static analysis tools (like mypy).Proposed Changes
Formal Type Definitions:
SHITEMIDandITEMIDLISTas properctypes.Structureclasses.LPITEMIDLISTandLPCITEMIDLISTcorrectly pointer to these structures.Interface Enhancements:
IShellLinkAandIShellLinkWvtables to use these formal types.hints.Incompletewith_Pointer[ITEMIDLIST]and explicitHRESULTreturns.Added Test Coverage:
test_shelllink.pyto verify round-tripping (Set/Get) ofITEMIDLIST.Benefits
Backward Compatibility
This change is expected to be highly backward compatible as
LPITEMIDLISTremains a pointer.Existing code treating it as a handle should continue to function without modification.