ikamensh / flynt

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

Assertion tracebacks too verbose #200

Open wimglenn opened 3 weeks ago

wimglenn commented 3 weeks ago

For an example like this:

FOO = "{}"
foo = FOO.format("foo")

The output of flynt -v is too verbose:

$ flynt example.py -v
Running flynt v.1.0.1
Using following options: Namespace(verbose=True, quiet=False, no_multiline=False, line_length=88, dry_run=False, stdout=False, string=False, transform_percent=True, transform_format=True, transform_concats=False, transform_joins=False, fail_on_change=False, aggressive=False, exclude=None, src=['example.py'], version=False)
Exception during conversion of code: Traceback (most recent call last):
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
                         ^^^^^^^^^^^^^^^^
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
             ^^^^^^^^^^^^^^
  File "/jump/software/rhel8/Python-3.12.6/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
                  ^^^^^^^^^^^^^^
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Traceback (most recent call last):
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
                         ^^^^^^^^^^^^^^^^
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
             ^^^^^^^^^^^^^^
  File "/jump/software/rhel8/Python-3.12.6/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
                  ^^^^^^^^^^^^^^
  File "/tmp/f/.venv/lib/python3.12/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
fstringifying /tmp/f/example.py...no change

Flynt run has finished. Stats:

Execution time:                            0.001s
Files checked:                             1
Files modified:                            0

_-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_._-_.
Please run your tests before committing. Did flynt get a perfect conversion? give it a star at: 
~ https://github.com/ikamensh/flynt ~
Thank you for using flynt. Upgrade more projects and recommend it to your colleagues!

It is normal/expected that flynt shouldn't rewrite this kind of example. Could the AssertionError traceback be hidden under an additional verbosity flag, e.g. -vv?

When formatting a large codebase, I like to see the messages about where flynt was not aggressive enough or not able to transform some code, but it's hard to see the forest for the trees when there are so many of these assertion tracebacks.

Thanks!