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 COM service that validates structured data and provides detailed error information when validation fails.
Create a Python COM server that validates data dictionaries against predefined rules. When validation fails, the service must use COM error information interfaces to provide:
The validator should support two types of validation rules:
Your implementation should:
When validation fails, use the appropriate comtypes functions to create and set error information that COM clients can retrieve.
When validating {"name": "John"} with a required field rule for "email", the validator raises a COM error with detailed error information accessible via IErrorInfo. @test
When validating {"age": "thirty"} with a type rule expecting "age" to be int, the validator raises a COM error with error information including description, IID, and help context. @test
When validating {"name": "Alice", "age": 25} with rules requiring "name" (str) and "age" (int), validation succeeds without raising errors. @test
@generates
from comtypes import COMObject, GUID, IUnknown, COMMETHOD
from ctypes import HRESULT
class IDataValidator(IUnknown):
"""COM interface for data validation with detailed error reporting"""
_iid_ = GUID("{...}") # Define appropriate GUID
# Define interface methods for:
# - Setting validation rules
# - Validating data
# - Retrieving validation results
class DataValidator(COMObject):
"""
COM server that validates data dictionaries and provides detailed error
information via IErrorInfo when validation fails.
"""
def __init__(self):
"""Initialize the validator with empty rule set"""
pass
def set_rules(self, rules: dict) -> None:
"""
Configure validation rules.
Args:
rules: Dictionary mapping field names to validation rules
Example: {"name": {"required": True, "type": str}}
"""
pass
def validate(self, data: dict) -> bool:
"""
Validate data against configured rules.
Args:
data: Dictionary to validate
Returns:
True if validation succeeds
Raises:
COMError with detailed error information (via IErrorInfo) if validation fails.
Error information should include description, IID, help file, and help context.
"""
passProvides COM interoperability for Python on Windows, including error reporting interfaces.