or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/comtypes@1.4.x
tile.json

tessl/pypi-comtypes

tessl install tessl/pypi-comtypes@1.4.0

Pure 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%

task.mdevals/scenario-1/

COM Data Type Converter Utility

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.

Requirements

Your module should implement the following functions:

1. Basic Type Conversion

Create a function convert_to_com(value) that converts Python basic types to their COM equivalents:

  • Python int values
  • Python float values
  • Python str values (should become BSTR)
  • Python bool values
  • Python datetime objects

2. Array Conversion

Create a function create_com_array(python_list, element_type) that converts a Python list to a COM SAFEARRAY. The function should:

  • Take a Python list and an element type specification
  • Return a properly configured SAFEARRAY that can be passed to COM methods
  • Support at least integer and string element types

3. Variant Handling

Create a function unwrap_variant(com_value) that takes a COM VARIANT and extracts the underlying Python value.

4. Currency Conversion

Create a function python_to_currency(decimal_value) that converts a Python Decimal or float to a COM CURRENCY type.

Implementation

@generates

API

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
    """
    pass

Test Cases

  • convert_to_com(42) returns a value that can be used in COM method calls @test
  • convert_to_com("hello") returns a BSTR-compatible value @test
  • create_com_array([1, 2, 3], 'int') returns a SAFEARRAY with integer elements @test
  • python_to_currency(123.45) returns a COM CURRENCY object @test

Dependencies { .dependencies }

comtypes { .dependency }

Provides COM interoperability and type conversion support for Windows.