Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe spurious traceback on calling .format on a variable #193

Open
Lalufu opened this issue Nov 14, 2023 · 0 comments
Open

Maybe spurious traceback on calling .format on a variable #193

Lalufu opened this issue Nov 14, 2023 · 0 comments

Comments

@Lalufu
Copy link

Lalufu commented Nov 14, 2023

While investingating some non-transformed files, I came across this case:

A = "foo.{bar}"


def foo(x):
    return A.format(x)

When running flynt on this in verbose mode, the following output appears:

Exception during conversion of code: Traceback (most recent call last):
  File "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
                         ^^^^^^^^^^^^^^^^
  File "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
             ^^^^^^^^^^^^^^
  File "/opt/blue-python/3.11/lib64/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
                  ^^^^^^^^^^^^^^
  File "~/venv/flynt/lib64/python3.11/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 "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/transform.py", line 32, in transform_chunk
    converted, changed = fstringify_node(
                         ^^^^^^^^^^^^^^^^
  File "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/FstringifyTransformer.py", line 88, in fstringify_node
    result = ft.visit(node)
             ^^^^^^^^^^^^^^
  File "/opt/blue-python/3.11/lib64/python3.11/ast.py", line 418, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    result_node = joined_string(
                  ^^^^^^^^^^^^^^
  File "~/venv/flynt/lib64/python3.11/site-packages/flynt/transform/format_call_transforms.py", line 18, in joined_string
    assert isinstance(fmt_call.func, ast.Attribute) and isinstance(
AssertionError
fstringifying ~/t.py...no change
Running flynt v.1.0.1
Using following options: Namespace(verbose=True, quiet=False, no_multiline=False, line_length=88, dry_run=True, 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=['./t.py'], version=False)
Running flynt in dry-run mode. No files will be changed.

Flynt run has finished. Stats:

Execution time:                            0.008s
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!

I can see why this would not work, but the traceback looks maybe a bit more scary than it needs to be?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant