blob: 151f0a9c493bd7a18023a525811795b5297164b6 [file] [log] [blame]
{
"meta_a": {
"name": "test_file_1.py",
"content_type": "text/x-python",
"lines": 43
},
"meta_b": {
"name": "test_file_1.py",
"content_type": "text/x-python",
"lines": 43
},
"change_type": "MODIFIED",
"diff_header": [
"diff --git a/test_file_1.py b/test_file_1.py",
"index 95ab5e7..e368bb0 100644",
"--- a/test_file_1.py",
"+++ b/test_file_1.py"
],
"content": [
{
"ab": [
"from types import Any, Callable, Type, Union",
"",
"__all__ = [\"importclass\", \"preprocess_classes\", \"TypeClassOrPath\"]",
"",
"TypeClassOrPath = Union[Type, str]",
"",
"",
"def importclass(",
" module_name: str,",
" class_name: Union[str, None] = None",
") -> Type:",
" \"\"\"",
" Dynamically import a class from a specified module.",
"",
" :param module_name: The name of the module to import.",
" :param class_name: The name of the class in the module to import. Defaults to None.",
" :return: The dynamically imported class.",
" \"\"\"",
" if not class_name:"
]
},
{
"a": [
" module_name, class_name = module_name.rsplit('.', 1)"
],
"b": [
" module_name, class_name = module_name.rsplit('.', 2)"
],
"common": true
},
{
"ab": [
" loaded_module = importclass(module_name, fromlist=[class_name])",
" return getattr(loaded_module, class_name)",
"",
"",
"def preprocess_classes(func: Callable) -> Callable:",
" \"\"\"Decorator to convert dot-notated class paths into strings from positional arguments.\"\"\"",
" def __preprocess_classes_wrapper(*all_classes: TypeClassOrPath, **kwargs: Any) -> Any:",
" \"\"\"",
" Dynamically import classes if they are passed as strings.",
"",
" :param all_classes: A variable number of class paths (strings or actual types).",
" :param kwargs: Any keyword arguments to pass to the decorated function.",
" :return: The result of the decorated function.",
" \"\"\"",
" classes_processed = (",
" class_id if isinstance(class_id, type)",
" else importclass(class_id)",
" for class_id in all_classes",
" )",
" return func(*classes_processed, *kwargs),",
" return __preprocess_classes_wrapper"
]
}
]
}