tessl install tessl/pypi-comtypes@1.4.0Pure Python COM package for Windows COM automation and interoperability
Agent Success
Agent success rate when using this tile
88%
Improvement
Agent success rate improvement when using this tile compared to baseline
0.99x
Baseline
Agent success rate without this tile
89%
Build a utility module that handles data type conversions between Python and COM for a Windows automation application. The module should provide functions to convert various Python data types to their COM equivalents and vice versa, handling arrays, basic types, and COM-specific types.
Your module should implement the following functions:
Create a function convert_to_com(value) that converts Python basic types to their COM equivalents:
int valuesfloat valuesstr values (should become BSTR)bool valuesdatetime objectsCreate a function create_com_array(python_list, element_type) that converts a Python list to a COM SAFEARRAY. The function should:
Create a function unwrap_variant(com_value) that takes a COM VARIANT and extracts the underlying Python value.
Create a function python_to_currency(decimal_value) that converts a Python Decimal or float to a COM CURRENCY type.
@generates
from decimal import Decimal
from datetime import datetime
from typing import Any, List
def convert_to_com(value: Any) -> Any:
"""
Convert Python basic types to COM equivalents.
Args:
value: Python value (int, float, str, bool, or datetime)
Returns:
COM-compatible representation of the value
"""
pass
def create_com_array(python_list: List, element_type: str) -> Any:
"""
Convert a Python list to a COM SAFEARRAY.
Args:
python_list: Python list to convert
element_type: Type of elements ('int' or 'str')
Returns:
SAFEARRAY compatible with COM methods
"""
pass
def unwrap_variant(com_value: Any) -> Any:
"""
Extract the Python value from a COM VARIANT.
Args:
com_value: COM VARIANT object
Returns:
Underlying Python value
"""
pass
def python_to_currency(decimal_value: float | Decimal) -> Any:
"""
Convert Python numeric value to COM CURRENCY type.
Args:
decimal_value: Python float or Decimal value
Returns:
COM CURRENCY object
"""
passconvert_to_com(42) returns a value that can be used in COM method calls @testconvert_to_com("hello") returns a BSTR-compatible value @testcreate_com_array([1, 2, 3], 'int') returns a SAFEARRAY with integer elements @testpython_to_currency(123.45) returns a COM CURRENCY object @testProvides COM interoperability and type conversion support for Windows.