Skip to content

Commit 4786cf7

Browse files
author
MomIsBestFriend
committed
Add option to ignore specific imports
1 parent 4ccf711 commit 4786cf7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

scripts/validate_unwanted_patterns.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,18 @@
1616
import sys
1717
import token
1818
import tokenize
19-
from typing import IO, Callable, Iterable, List, Tuple
19+
from typing import IO, Callable, Iterable, List, Set, Tuple
2020

2121
FILE_EXTENSIONS_TO_CHECK: Tuple[str, ...] = (".py", ".pyx", ".pxi.ini", ".pxd")
2222
PATHS_TO_IGNORE: Tuple[str, ...] = ("asv_bench/env",)
2323

24+
PRIVATE_IMPORTS_TO_IGNORE: Set[str] = {
25+
"_extension_array_shared_docs",
26+
"_index_shared_docs",
27+
"_merge_doc",
28+
"_shared_docs",
29+
}
30+
2431

2532
def _get_literal_string_prefix_len(token_string: str) -> int:
2633
"""
@@ -138,8 +145,13 @@ def private_function_across_module(file_obj: IO[str]) -> Iterable[Tuple[int, str
138145
if not (isinstance(node, ast.Import) or isinstance(node, ast.ImportFrom)):
139146
continue
140147

141-
if any(mod.name.split(".")[-1].startswith("_") for mod in node.names):
142-
yield (node.lineno, "Use of private function across modules found.")
148+
for module in node.names:
149+
module_name = module.name.split(".")[-1]
150+
if module_name in PRIVATE_IMPORTS_TO_IGNORE:
151+
continue
152+
153+
if module_name.startswith("_"):
154+
yield (node.lineno, f"Import of internal function {repr(module_name)}")
143155

144156

145157
def strings_to_concatenate(file_obj: IO[str]) -> Iterable[Tuple[int, str]]:

0 commit comments

Comments
 (0)