MCPcopy
hub / github.com/pandas-dev/pandas / private_import_across_module

Function private_import_across_module

scripts/validate_unwanted_patterns.py:153–180  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

151
152
153def 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
183def strings_with_wrong_placed_whitespace(

Callers

nothing calls this directly

Calls 5

walkMethod · 0.80
splitMethod · 0.80
startswithMethod · 0.80
readMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected