|
12 | 12 |
|
13 | 13 | def get_qualified_name(module_name: str, full_qualified_name: str) -> str: |
14 | 14 | if not full_qualified_name: |
15 | | - raise ValueError("full_qualified_name cannot be empty") |
| 15 | + msg = "full_qualified_name cannot be empty" |
| 16 | + raise ValueError(msg) |
16 | 17 | if not full_qualified_name.startswith(module_name): |
17 | 18 | msg = f"{full_qualified_name} does not start with {module_name}" |
18 | 19 | raise ValueError(msg) |
@@ -46,9 +47,9 @@ def file_name_from_test_module_name(test_module_name: str, base_dir: Path) -> Pa |
46 | 47 | def get_imports_from_file( |
47 | 48 | file_path: Path | None = None, file_string: str | None = None, file_ast: ast.AST | None = None |
48 | 49 | ) -> list[ast.Import | ast.ImportFrom]: |
49 | | - assert ( |
50 | | - sum([file_path is not None, file_string is not None, file_ast is not None]) == 1 |
51 | | - ), "Must provide exactly one of file_path, file_string, or file_ast" |
| 50 | + assert sum([file_path is not None, file_string is not None, file_ast is not None]) == 1, ( |
| 51 | + "Must provide exactly one of file_path, file_string, or file_ast" |
| 52 | + ) |
52 | 53 | if file_path: |
53 | 54 | with file_path.open(encoding="utf8") as file: |
54 | 55 | file_string = file.read() |
@@ -107,6 +108,14 @@ def validate_python_code(code: str) -> str: |
107 | 108 | return code |
108 | 109 |
|
109 | 110 |
|
| 111 | +def has_any_async_functions(code: str) -> bool: |
| 112 | + try: |
| 113 | + module = ast.parse(code) |
| 114 | + except SyntaxError: |
| 115 | + return False |
| 116 | + return any(isinstance(node, ast.AsyncFunctionDef) for node in ast.walk(module)) |
| 117 | + |
| 118 | + |
110 | 119 | def cleanup_paths(paths: list[Path]) -> None: |
111 | 120 | for path in paths: |
112 | 121 | path.unlink(missing_ok=True) |
0 commit comments