-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Regression in python3.10 with traceback frame having lineno of -1 #88099
Comments
This is breaking pytest for failed assertions: pytest-dev/pytest#8227 It also breaks the traceback in the output below Here's a minimal example: class Boom:
def __enter__(self):
return self
def __exit__(self, *_):
raise AssertionError('boom!')
def main() -> int:
with Boom():
raise AssertionError('hi')
if __name__ == '__main__':
exit(main()) On python3.9 you get this:
output in python3.10:
Notice the second to last frame is now missing and invalid (line -1) I bisected this and found this is the culprit:
which appears to be due to bpo-42908 |
Marking as release blocker since is breaking pytest |
Thanks for the bisection, Anthony |
What exactly is the issue here? The The traceback for 3.9 is incorrect, the program is not on line 10 when __exit__ is called. Currently we mark the cleanup code for the with statement as artificial meaning that it has no line number. PEP-626 says that the "with" keyword is executable, and should be traced, but nothing about whether that includes the cleanup call to __exit__. |
Mark, you say:
It's kind of not on any line in main(), but line 10 is the most useful line to indicate. It's the last bit of the user's code that was running, and it is the reason for leaving the with statement. |
In this case, if happens that line 10 was the last line of code executing in the body of the with statement. If the body is something like:
Then the reported last line will be 4, even though it is never executed. |
This test case was added for 3.10. https://github.com/python/cpython/blob/master/Lib/test/test_sys_settrace.py#L919 |
Please don't lose the big picture here. If, in an effort to make line numbers *exact*, we determine that there's no good line number to report and use -1 or None, we're introducing a regression.
That sounds like a reasonable idea, despite the drawback. As we can see from the report, *any* change will probably break *some* tools. |
I'm going to set the line number for executing the This should give a sensible traceback, and not break coverage, as the with statement is already executed. Anthony, Ned, |
I'm claiming that this is fixed. Feel free to reopen if the additional line in tracing causes a problem. |
Thanks Mark for the quick fix! Can someone confirm if the pytest issue is fixed? |
can confirm that pytest no longer crashes |
I'm trying to see if these changes affect coverage.py, but pytest 6.2.3 fails with: === CPython 3.10.0a7+ (rev 558df90) with Python tracer (.tox/anypy/bin/python) === Is this something I am doing wrong? |
ah yeah that's the |
Thanks, tip of pytest works for me. Is this error going to happen for everyone testing with 3.10b1? If so, can we get a release of pytest? |
3.10.0b1 includes both of these PRs so people testing the beta should not get affected. That's why I marked this as release blocker. |
The pytest failure still happens with 3.10.0b1 and pytest 6.2.3. I'm asking if pytest can make a release to update. |
What I am missing? 3.10.0b1 includes the fixes for this issue, no? Is it because the fixes still require some changes in the source? If that's the case, we should mention it in the What's New
In any case, shouldn't that be requested in the pytest issue tracker? |
I've released pytest 6.2.4 for the other breakage (which is unrelated to this bpo -- it was the asname source position issue) |
Mark, I'm not clear if the line number can still be None in some circumstances. With this code (from site.py in the stdlib): 545: def execsitecustomize(): I get traces with these events and line numbers: exception 549 (ModuleNotFoundError("No module named 'sitecustomize'")) Is this what you expected? |
Ned, no line numbers should never be None. Taking a look at the disassembly of execsitecustomize, there is a return with no line number, which shouldn't happen. |
BTW, I created a separate issue about this: https://bugs.python.org/issue44088 because I wasn't sure if I should continue on this one, sorry. Feel free to close either one. |
Thanks, this fixes my issue. |
See also bpo-44297. |
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: