Skip to content

Commit

Permalink
better repr
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Oct 29, 2024
1 parent ed17b66 commit 8eea973
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions lib/python/pyflyby/_autoimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -443,6 +450,7 @@ def scan_for_import_issues(self, codeblock: PythonBlock):
# references in doctests to be noted as missing-imports. For now we
# just let the code accumulate into self.missing_imports and ignore
# the result.
logger.debug("unused: %r", self.unused_imports)
missing_imports = sorted(self.missing_imports)
if self.parse_docstrings and self.unused_imports is not None:
doctest_blocks = codeblock.get_doctests()
Expand Down Expand Up @@ -923,9 +931,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)
Expand Down
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_importstmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8eea973

Please sign in to comment.