ikamensh / flynt

A tool to automatically convert old string literal formatting to f-strings
MIT License
689 stars 33 forks source link

Crash when using line length, -ll 999 #185

Closed kwloafman closed 1 year ago

kwloafman commented 1 year ago

Running on macOS 12.6.7 and using python 3.11.

When running flynt -v -a -ll 999 . I get a lot of tracebacks like this:

Skipping fstrings transform of file /Users/ken/workspace/duplicity-py3/testing/unit/test_gpginterface.py due to unsupported operand type(s) for -: 'str' and 'int'.
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/flynt/api.py", line 92, in fstringify_content
    new_code, changes = fstringify_code_by_line(
                        ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flynt/process.py", line 179, in fstringify_code_by_line
    return _transform_code(
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flynt/process.py", line 219, in _transform_code
    ).fstringify_code_by_line()
      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/flynt/process.py", line 57, in fstringify_code_by_line
    self.try_chunk(chunk)
  File "/usr/local/lib/python3.11/site-packages/flynt/process.py", line 109, in try_chunk
    self.maybe_replace(chunk, contract_lines, converted, rest)
  File "/usr/local/lib/python3.11/site-packages/flynt/process.py", line 128, in maybe_replace
    len(f"{converted}{rest}") <= self.len_limit - chunk.start_idx
                                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'

I have a lot of ' % ' strings to convert to f-string and they are multiline. None of these get converted.

ikamensh commented 1 year ago

Hey, thanks for the bug report. Can you also give me flynt version with flynt --version? it's installed with pip install ?

ikamensh commented 1 year ago

p.s. one more request - could you try the latest version with pip install https://github.com/ikamensh/flynt/archive/refs/heads/master.zip and tell me if the bug persists?

kwloafman commented 1 year ago

Version was 0.78 via pip3. Thanks for the quick fix!