Checking that a private function is not imported across modules. Parameters ---------- file_obj : IO File-like object containing the Python code to validate. Yields ------ line_number : int Line number of import statement, that imports the private functio
(file_obj: IO[str])
| 151 | |
| 152 | |
| 153 | def private_import_across_module(file_obj: IO[str]) -> Iterable[tuple[int, str]]: |
| 154 | """ |
| 155 | Checking that a private function is not imported across modules. |
| 156 | Parameters |
| 157 | ---------- |
| 158 | file_obj : IO |
| 159 | File-like object containing the Python code to validate. |
| 160 | Yields |
| 161 | ------ |
| 162 | line_number : int |
| 163 | Line number of import statement, that imports the private function. |
| 164 | msg : str |
| 165 | Explanation of the error. |
| 166 | """ |
| 167 | contents = file_obj.read() |
| 168 | tree = ast.parse(contents) |
| 169 | |
| 170 | for node in ast.walk(tree): |
| 171 | if not isinstance(node, (ast.Import, ast.ImportFrom)): |
| 172 | continue |
| 173 | |
| 174 | for module in node.names: |
| 175 | module_name = module.name.split(".")[-1] |
| 176 | if module_name in PRIVATE_IMPORTS_TO_IGNORE: |
| 177 | continue |
| 178 | |
| 179 | if module_name.startswith("_"): |
| 180 | yield (node.lineno, f"Import of internal function {module_name!r}") |
| 181 | |
| 182 | |
| 183 | def strings_with_wrong_placed_whitespace( |
nothing calls this directly
no test coverage detected