From 19c71fe9237d6cd93cd5085eef58ffcb0f5fa290 Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Tue, 29 Oct 2024 13:29:40 +0100 Subject: [PATCH] More debug/repr information and type annotations --- lib/python/pyflyby/_autoimp.py | 18 ++++++++++++------ lib/python/pyflyby/_importstmt.py | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/python/pyflyby/_autoimp.py b/lib/python/pyflyby/_autoimp.py index 81917a8b..d6cc4acb 100644 --- a/lib/python/pyflyby/_autoimp.py +++ b/lib/python/pyflyby/_autoimp.py @@ -341,17 +341,24 @@ def symbol_needs_import(fullname, namespaces): return True -class _UseChecker(object): +class _UseChecker: """ An object that can check whether it was used. """ - used = False - def __init__(self, name, source, lineno): + used: bool = False + name: str + source: str + lineno: int + + def __init__(self, name: str, source: str, lineno: int): self.name = name self.source = source # generally an Import self.lineno = lineno + def __repr__(self): + return f"<{type(self).__name__}: name:{self.name} source:{self.source!r} lineno:{self.lineno} used:{self.used}>" + class _MissingImportFinder: """ @@ -923,9 +930,8 @@ def _visit_fullname(self, fullname, ctx): def _visit_StoreImport(self, node, modulename): name = node.asname or node.name - logger.debug("_visit_StoreImport(asname=%r,name=%r)", - node.asname, node.name) - is_star = node.name == '*' + logger.debug("_visit_StoreImport(asname=%r, name=%r)", node.asname, node.name) + is_star = node.name == "*" if is_star: logger.debug("Got star import: line %s: 'from %s import *'", self._lineno, modulename) diff --git a/lib/python/pyflyby/_importstmt.py b/lib/python/pyflyby/_importstmt.py index bf285095..6179fac9 100644 --- a/lib/python/pyflyby/_importstmt.py +++ b/lib/python/pyflyby/_importstmt.py @@ -96,7 +96,7 @@ class NonImportStatementError(TypeError): """ @total_ordering -class Import(object): +class Import: """ Representation of the desire to import a single name into the current namespace.