ikamensh / flynt

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

flynt raising in matching_call because of missing value attribute #103

Closed jrett2 closed 3 years ago

jrett2 commented 3 years ago

I'm getting this for a ton of files in my repo: AttributeError: 'Name' object has no attribute 'value' from matching_call()

Exception 'Name' object has no attribute 'value' during conversion of code '"{}/{}" . format ( super ( SuggestEndpoint , self ) . path , self . facet . suggest )'
Traceback (most recent call last):
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/transform.py", line 29, in transform_chunk
    converted, changed, str_in_str = fstringify_node(copy.deepcopy(tree))
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/FstringifyTransformer.py", line 91, in fstringify_node
    result = ft.visit(node)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 439, in generic_visit
    value = self.visit(value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 448, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    self.visit(result_node)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 439, in generic_visit
    value = self.visit(value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 448, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 448, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/FstringifyTransformer.py", line 21, in visit_Call
    match = matching_call(node)
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/format_call_transforms.py", line 33, in matching_call
    call_from_string = isinstance(node.func.value, ast.Str) or (
AttributeError: 'Name' object has no attribute 'value'
Exception 'Name' object has no attribute 'value' during conversion of code '"Running test case {} of {}" . format ( i + 1 , len ( test_cases ) )'
Traceback (most recent call last):
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/transform.py", line 29, in transform_chunk
    converted, changed, str_in_str = fstringify_node(copy.deepcopy(tree))
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/FstringifyTransformer.py", line 91, in fstringify_node
    result = ft.visit(node)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 439, in generic_visit
    value = self.visit(value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 448, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/FstringifyTransformer.py", line 31, in visit_Call
    self.visit(result_node)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 439, in generic_visit
    value = self.visit(value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/usr/lib/python3.8/ast.py", line 448, in generic_visit
    new_node = self.visit(old_value)
  File "/usr/lib/python3.8/ast.py", line 363, in visit
    return visitor(node)
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/FstringifyTransformer.py", line 21, in visit_Call
    match = matching_call(node)
  File "/home/jrett/venv/qa/lib/python3.8/site-packages/flynt/transform/format_call_transforms.py", line 33, in matching_call
    call_from_string = isinstance(node.func.value, ast.Str) or (
AttributeError: 'Name' object has no attribute 'value'
(qa) jrett@ts-prod:~/src/qa$ pip freeze
antlr4-python3-runtime==4.8
appdirs==1.4.4
astor==0.8.1
astroid==2.5.3
attrs==20.3.0
bcrypt==3.2.0
beautifulsoup4==4.9.3
black==20.8b1
bottle==0.12.19
certifi==2020.12.5
cffi==1.14.5
chardet==4.0.0
click==7.1.2
cryptography==3.4.7
daemonize==2.5.0
docker==5.0.0
flynt==0.64
idna==2.10
iniconfig==1.1.1
isort==5.8.0
Js2Py==0.71
lazy-object-proxy==1.6.0
library-logging==1.1.2
lxml==4.6.3
mccabe==0.6.1
mypy-extensions==0.4.3
mysql-connector-python==8.0.24
natsort==7.1.1
ncclient==0.6.10
packaging==20.9
parameterized==0.8.1
paramiko==2.7.2
pathspec==0.8.1
pep517==0.10.0
pexpect==4.8.0
Pillow==8.2.0
pip-tools==6.1.0
pluggy==0.13.1
plumbum==1.7.0
ply==3.11
postgrest-client==1.0.4
protobuf==3.15.8
psycopg2-binary==2.8.6
ptyprocess==0.7.0
py==1.10.0
pyasn1==0.4.8.1
pycparser==2.20
pycryptodomex==3.10.1
pyflakes==2.3.1
pyjsparser==2.7.1
pylint==2.7.4
PyNaCl==1.4.0
pyparsing==2.4.7
pysmi==0.3.4
pysnmp==4.4.12
pytest==6.2.3
python-box==5.3.0
python-dateutil==2.8.1
python-magic==0.4.22
pytz==2021.1
pyvmomi==7.0.2
PyYAML==5.4.1
regex==2021.4.4
requests==2.25.1
requests-mock==1.8.0
requests-toolbelt==0.9.1
rpyc==5.0.1
rstr==2.2.6
scapy==2.4.5
selenium==3.141.0
simplejson==3.17.2
six==1.15.0
soupsieve==2.2.1
stix2==2.1.0
stix2-patterns==1.3.2
suds-jurko==0.6
tabulate==0.8.9
toml==0.10.2
typed-ast==1.4.3
typing-extensions==3.7.4.3
tzlocal==2.1
urllib3==1.26.4
websocket-client==0.58.0
wrapt==1.12.1
jrett2 commented 3 years ago

This broke here in 5527be091ecbc6cef5911961d3c2707a0dc7f363

call_from_string is being evaluated before the hasattr(node.func, "value") now, so any time the value attr is missing this crashes.

ikamensh commented 3 years ago

Thanks for the report and your patience :) should be fixed now.