From f0221b72b479b5f141193f441f6398af692a7ed4 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Wed, 27 Nov 2024 14:04:10 +0200 Subject: [PATCH] Refactoring: remove some Python-2-isms --- findimports.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/findimports.py b/findimports.py index 4fd5c06..07b6e6e 100755 --- a/findimports.py +++ b/findimports.py @@ -64,7 +64,7 @@ findimports.py -u will not complain about import statements that have a comment on the same line, e.g.: - from somewhereelse import somename # reexport + from somewhereelse import somename # reexport findimports.py -u -a will ignore comments and print these statements also. @@ -352,8 +352,6 @@ def processDocstring(self, docstring, lineno, depth): for example in examples: try: source = example.source - if not isinstance(source, str): - source = source.encode('UTF-8') # pragma: PY2 node = ast.parse(source, filename='') except SyntaxError: print("{filename}:{lineno}: syntax error in doctest".format( @@ -403,7 +401,7 @@ class ImportFinderAndNameTracker(ImportFinder): verbose = False def __init__(self, filename, max_depth=None): - ImportFinder.__init__(self, filename, max_depth) + super().__init__(filename, max_depth) self.scope = self.top_level = Scope(name=filename) self.scope_stack = [] self.unused_names = [] @@ -425,17 +423,16 @@ def leaveAllScopes(self): def processDocstring(self, docstring, lineno, depth): self.newScope(self.top_level, 'docstring') - ImportFinder.processDocstring(self, docstring, lineno, depth) + super().processDocstring(docstring, lineno, depth) self.leaveScope() def visit_FunctionDef(self, node, depth): self.newScope(self.scope, f"function {node.name}") - ImportFinder.visit_FunctionDef(self, node, depth) + super().visit_FunctionDef(node, depth) self.leaveScope() def processImport(self, name, imported_as, full_name, level, node): - ImportFinder.processImport( - self, name, imported_as, full_name, level, node) + super().processImport(name, imported_as, full_name, level, node) if not imported_as: imported_as = name if imported_as != "*": @@ -472,7 +469,7 @@ def visit_Attribute(self, node, depth): if name: name = f"{name}.{part}" else: - name += part + name = part self.scope.useName(name) self.generic_visit(node, depth)