sqlalchemyorg / zimports

Python import rewriter
MIT License
75 stars 6 forks source link

crashes on TYPE_CHECKING block that has no imports #31

Closed zzzeek closed 2 years ago

zzzeek commented 2 years ago
import typing

if typing.TYPE_CHECKING:
    print("hi")
Traceback (most recent call last):
  File "/home/classic/.venv3/bin/zimports", line 33, in <module>
    sys.exit(load_entry_point('zimports', 'console_scripts', 'zimports')())
  File "/home/classic/dev/zimports/zimports/cli.py", line 110, in main
    run_with_options(options)
  File "/home/classic/dev/zimports/zimports/zimports.py", line 854, in run_with_options
    _run_file(options, filename)
  File "/home/classic/dev/zimports/zimports/zimports.py", line 798, in _run_file
    result, stats = Rewriter(options, filename, source_lines).rewrite()
  File "/home/classic/dev/zimports/zimports/zimports.py", line 160, in rewrite
    rewritten = self._do_rewrite(self.source_lines, type_check_pass=True)
  File "/home/classic/dev/zimports/zimports/zimports.py", line 103, in _do_rewrite
    imports, warnings, lines_with_code = _parse_toplevel_imports(
  File "/home/classic/dev/zimports/zimports/zimports.py", line 459, in _parse_toplevel_imports
    tree = ast.parse(source, filename)
  File "/opt/python-3.10.0/lib/python3.10/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
  File "test3.py", line 5
    print("hi")
IndentationError: unexpected indent