You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Wrong reported location for undefined references in f-strings #3562
"""mypy test: location for undefined references in f-strings"""fromtypingimportListmy_list: List[str] = ['Anna', 'Jonathan', 'Sandra', 'Joseph']
print(f'My list has {len(my_list)} elements.')
print('The list has %i elements.'%len(my_wrong_list))
print(f'The list has {len(another_wrong_list)} elements.')
print(f'The list has {missing_integer} elements.')
print('The list has {0:d} elements.'.format(len(yet_another_wrong_list)))
I get (mypy 0.520-dev):
> mypy --python-version 3.6 --show-column-numbers --check-untyped-defs test_mypy.py
test_mypy.py:1:5: error: Name 'another_wrong_list' is not defined
test_mypy.py:8:40: error: Name 'my_wrong_list' is not defined
test_mypy.py:10:6: error: Name 'missing_integer' is not defined
test_mypy.py:11:48: error: Name 'yet_another_wrong_list' is not defined
I'd expect:
mypy --python-version 3.6 --show-column-numbers --check-untyped-defs test_mypy.py
test_mypy.py:8:40: error: Name 'my_wrong_list' is not defined
test_mypy.py:9:26: error: Name 'another_wrong_list' is not defined
test_mypy.py:10:22: error: Name 'missing_integer' is not defined
test_mypy.py:11:48: error: Name 'yet_another_wrong_list' is not defined
So, for references in built-in functions in f-strings, both line and column are wrong (line is always reported as being the 1st, so these messages become the first ones reported by mypy) and for plain references in f-strings, just the reported column is wrong. Hope this helps.
If it's fixed in master (or 3.6) upstream it can be fixed in typed_ast, there's no need to wait for a CPython release. But there needs to be a separate PR for typed_ast (it doesn't automatically get copied from CPython nor does it somehow invoke the CPython version).
I opened an issue against typed_ast (python/typed_ast#56) to copy the fix there (but I'm not personally going to do the busy-work of creating the PR).
Activity
emmatyping commentedon Jun 16, 2017
@ambv you were working on something related to this, no? It was a CPython issue as I recall? Or was that a different issue related to f-strings?
ambv commentedon Jun 16, 2017
Yes, this is bpo-30465 and the fix is in python/cpython#1800 but I won't have time before July to finish it.
FichteFoll commentedon Sep 15, 2017
The referenced patch/PR has been merged into master and the 3.6 branch, so hopefully this will be resolved with the next CPython release.
emmatyping commentedon Sep 15, 2017
The actual fix for mypy will happen when typed_ast is updated, which should be when the next Python version is released, but may be sooner.
emmatyping commentedon Sep 15, 2017
Also, this is an issue with typed_ast, so I am closing this.
gvanrossum commentedon Sep 15, 2017
If it's fixed in master (or 3.6) upstream it can be fixed in typed_ast, there's no need to wait for a CPython release. But there needs to be a separate PR for typed_ast (it doesn't automatically get copied from CPython nor does it somehow invoke the CPython version).
I opened an issue against typed_ast (python/typed_ast#56) to copy the fix there (but I'm not personally going to do the busy-work of creating the PR).