Skip to content

Commit c69a748

Browse files
committed
strict typing
1 parent 5a49ef7 commit c69a748

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

scripts/check_for_inconsistent_pandas_namespace.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030

3131
class Visitor(ast.NodeVisitor):
32-
def __init__(self):
32+
def __init__(self) -> None:
3333
self.pandas_namespace: MutableMapping[Offset, str] = {}
3434
self.no_namespace: Set[str] = set()
3535

@@ -42,13 +42,15 @@ def visit_Attribute(self, node: ast.Attribute) -> None:
4242
self.pandas_namespace[Offset(node.lineno, node.col_offset)] = node.attr
4343
self.generic_visit(node)
4444

45-
def visit_Name(self, node: ast.Name):
45+
def visit_Name(self, node: ast.Name) -> None:
4646
if node.id not in EXCLUDE:
4747
self.no_namespace.add(node.id)
4848
self.generic_visit(node)
4949

5050

51-
def check_for_inconsistent_pandas_namespace(content, path, *, replace):
51+
def check_for_inconsistent_pandas_namespace(
52+
content: str, path: str, *, replace: bool
53+
) -> Optional[str]:
5254
tree = ast.parse(content)
5355

5456
visitor = Visitor()
@@ -76,7 +78,8 @@ def check_for_inconsistent_pandas_namespace(content, path, *, replace):
7678
# Replace `.`
7779
tokens[n + 1] = i._replace(src="")
7880

79-
return tokens_to_src(tokens)
81+
new_src: str = tokens_to_src(tokens)
82+
return new_src
8083

8184

8285
def main(argv: Optional[Sequence[str]] = None) -> None:
@@ -91,7 +94,7 @@ def main(argv: Optional[Sequence[str]] = None) -> None:
9194
new_content = check_for_inconsistent_pandas_namespace(
9295
content, path, replace=args.replace
9396
)
94-
if not args.replace:
97+
if not args.replace or new_content is None:
9598
continue
9699
with open(path, "w", encoding="utf-8") as fd:
97100
fd.write(new_content)

0 commit comments

Comments
 (0)