-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
fix backslash in f-string #1838
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these changes (applied manually to 7.6.1), the synthetic extra lines in #1836 are now gone. (Tested with Python 3.11 and 3.12.)
@the-13th-letter Thanks for your careful tests in #1828 (comment) ! But I don't understand very much because I am not a native English speaker. In #1828 (comment), do you mean the same as the table below ?
I tested these four scenarios below and It seems like this PR(#1838) can fix your problem in both Python3.11 and Python3.12. So can I understand you like this:
Please let me know if I'm wrong. |
@LiuYinCarl, no, that's not what I mean. In #1828, I can trigger the opposite effect: backslash continuation sometimes disappears in the HTML report, so a line break is missing, and coverage info gets "shifted upwards". Specifically, in the following pytest-style file
|
fix typo.
fix code lint.
The attached patch contains a pytest test function to check for #1836. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code passes my recent test file on Python 3.11 and 3.12.
LGTM.
@LiuYinCarl @the-13th-letter Does one of you want to apply that new test to this pull request? Then we'd be able to merge it. @the-13th-letter Why use |
@the-13th-letter also, maybe we can do without |
Sorry, I went ahead and made a pull request with the test: LiuYinCarl#1 |
test: add a test for nedbat#1836, by Marco Ricci
@nedbat, your PR was merged and I add a annotation in this line to make it pass the tox checks. https://github.com/nedbat/coveragepy/pull/1838/files#diff-29c93c7c1984a5716eb3a992a5e15cdcf5b7471539f0cc2831f141cc780a0885R1210 |
Just to follow up:
It's a transcription of my original
Sure, go ahead. It'd be a style violation in my corner of the world to not use double quotes, but of course that doesn't necessarily apply here. (It does mean that this is the first solution that comes to mind, though.) |
Looking at the coverage reports for phystokens.py, there are some partial branches in the new checks: Is that because it's impossible for those conditions to be false, or because we are missing some test cases in the test suite? Either way, it would be great to resolve so that we don't have partial branches in the coverage report. |
@nedbat It's my opinion below. It is impossible for the condition on line 74 to be false because I'm not sure about line 69, but I have tested the cases in #1828 and #1838, and it is impossible for any tests on line 69 to fail. So, I think we can just replace the two conditions with |
@nedbat I too am mostly convinced that the condition on line 74 must always be true because of the Like @LiuYinCarl, I'm not so sure about line 69 either. I did however try to design (failing) test cases for that condition, without success. Thus, pragmatically, I would convert that condition into an assertion as well, and leave a note à la "We failed to design a test case that doesn't fulfill this condition.". attempted test inputs that don't improve branch coveragespace = " "
string = f"""\
line{space}1\
and still line{space}1
line 2 \
and still line 2\
and yet still line 2
line{space}3\
{space}and still line 3
""" space = " "
weird_formatting = {"empty_string": """\
""", "nonempty_string": """ \
\
""",\
"chunked_string": "hello"\
" "\
"world"}
weird_formatting_with_fstrings = {f"empty_string": f"""\
""", f"nonempty_string": f""" \
\
""",\
f"chunked_string": f"hello"\
f"{space}"\
f"world"} |
Thanks to both of you for continuing to work on this. I really appreciate it! <3 |
Updated in commit 595ea22, coverage changed from 95.256% to 95.266% :) |
This is now released as part of coverage 7.6.2. |
Fix #1836