-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Incorrect exception highlighting for fstring format #89048
Comments
Given this code: print(f"Here is that pesky {xxx/2:.3f} again") The traceback prints: Traceback (most recent call last):
File "/home/pablogsal/github/python/main/lel.py", line 1, in <module>
print(f"Here is that pesky {xxx/2:.3f} again")
^^^
NameError: name 'xxx' is not defined Removing the formatting part ":.3f" makes it work as expected |
(I originally reported this.) |
The problem lies here: cpython/Parser/string_parser.c Lines 374 to 389 in f66d00f
The problem is that the strstr call will fail because the string containing the expression doesn't have the formatting part in it, so the offsets never get corrected. |
Actually, this has even more problems. Because we are using strstr to find the start of the expression in the parent string, if the expression is repeated the offsets are incorrectly generated: For example: print(f"Here is that {xxx} pesky {xxx} again") This produces: ... while print(f"Here is that {xxx} pesky {xxxx} again") (different variables) produces: ... |
Ha, we have test that knows is broken: cpython/Lib/test/test_fstring.py Line 217 in f66d00f
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: