-
Notifications
You must be signed in to change notification settings - Fork 25
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 detection of self-documenting f-strings #39
Comments
Thanks for noticing, @GjjvdBurg! Looking at it now. :) |
There were some cases I hadn't noticed the first time around. Thanks again! |
Actually there are more cases (tested on Python 3.8 on your patch just now): Case 1 Case 2 Case 3 Unfortunately, "self-documenting f-string" or "f-string debugging" is poorly documented in the official documentation (I can only find it in whatsnew and changelog). The PR introducing this change contains some useful information (especially the test cases), along with its corresponding issue (contains relevant discussion when introducing this feature, might be a bit noisy because some previous proposals mentioned were rejected). |
Thanks, @gousaiyang :) Looking into it. |
I already implemented support for named expressions actually, but the sub node wasn't getting visited. So now
|
Also, visit sub nodes of f-strings. Related to #39.
Nice test cases. Have to include those, too. |
Okay, that should be all the remaining cases. Phew.. |
I just realized that the false positives happen because the Unfortunately, this means that
So it seems impossible to differentiate |
Yes, you are exactly right. I've run into this a number of times for different features, and as also mentioned in #35, I've thought about maybe utilizing an additional parser. But it would still be required to function with Python 2.7/3.0, and I still prefer the standard The source visitor class is given the parsed AST (because errors need to be handled beforehand due to the concurrent behavior), but it could perhaps be given the entire source in string form as well if any extra parsing is necessary - like parsing the |
There are still trivial cases tripping this so please re-open. E.g:
|
Sorry for the slow reply. The problem, as already described above, is that With this in mind, I think it would make more sense to disable the entire self-doc f-string detection (but keeping regular f-string detection, of course). |
This is done since the built-in AST cannot distinguish `f'{a=}'` from `f'a={a}'`, for instance, because it optimizes some information away. And this incorrectly marks some source code as using fstring self-doc when only using general fstring.
This is done since the built-in AST cannot distinguish `f'{a=}'` from `f'a={a}'`, for instance, because it optimizes some information away. And this incorrectly marks some source code as using fstring self-doc when only using general fstring.
Describe the bug
False-positives are returned for self-documenting f-strings.
To Reproduce
Expected behavior
Expected the minimum required version for this code to be 3.6. A self-documenting f-string has the equals sign on the other side of the variable (i.e.
{a=}
).Environment (please complete the following information):
Thanks in advance!
The text was updated successfully, but these errors were encountered: