sqlalchemyorg / zimports

Python import rewriter
MIT License
75 stars 6 forks source link

IndexError when running zimports on an empty file #16

Closed schmir closed 4 years ago

schmir commented 4 years ago

zimports 0.2.1 crashes with an IndexError when trying to read an empty file. This is a regression from 0.2.0:

ralf@triton ~/t % touch __init__.py
ralf@triton ~/t % zimports __init__.py 
Traceback (most recent call last):
  File "/home/ralf/.local/bin/zimports", line 8, in <module>
    sys.exit(main())
  File "/home/ralf/.local/pipx/venvs/zimports/lib64/python3.8/site-packages/zimports.py", line 766, in main
    _run_file(options, filename)
  File "/home/ralf/.local/pipx/venvs/zimports/lib64/python3.8/site-packages/zimports.py", line 622, in _run_file
    lines, encoding_comment = _read_python_source(filename)
  File "/home/ralf/.local/pipx/venvs/zimports/lib64/python3.8/site-packages/zimports.py", line 560, in _read_python_source
    if text[-1] == "\n":
IndexError: string index out of range
zzzeek commented 4 years ago

ok that one is coming