-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
Trackstack includes __exit__
in contextlib
which is not in previous versions
#92118
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
Comments
In case it helps, here's a minimal example of what this looks like:
|
cc @brandtbucher (since you asked me to tag you) |
I'm looking, this was caused by: commit 396b583
|
Thanks @iritkatriel |
I get the old traceback with this change:
The question now is which beaviour we prefer. I'll make a PR so that we can discuss. |
I think I prefer the 3.10 behavior, so just send the PR. |
…contextlib.contextmanager
PR is here: #92202 |
Wow, you are an expert of fixing tracebacks @iritkatriel! Should this be fixed in |
Thanks
I don’t think it can be fixed in the core code. We used to propagate the traceback separately from the exception in the (exc, val, tb) triplet. Now we don’t, we always take the traceback from the exception instance. So modifications to the exception are visible. I don’t think all context managers do this, but we might run into a few more cases. |
I mean that setting What was the behavior of |
Ah yes, that would fix this case. But it would also prevent you from changing the traceback in the exit block if you want to.
Good question. I don't see any tests for traceback with ExitStack (there are some tests for the context links). We should add some. I'm heading back to London soon. @serhiy-storchaka - feel free to merge the PR if you think its ready (we can work on ExitStack separately). Or if you have further comments I'll follow up tomorrow/Thursday. |
__exit__
in contextlib
whcih is not in previous versions__exit__
in contextlib
which is not in previous versions
…ExitStack.__exit__
I made a PR to add a test for ExitStack. This test passes on 3.10 as well, so there was no change there: #92339 I think it's unfortunate that the traceback contains so many frames from contextlib (from the dance it does to set |
…(Async)ExitStack.__exit__ (pythonGH-92339) (cherry picked from commit e65e587) Co-authored-by: Irit Katriel <[email protected]>
Thank you for reporting this @Cheukting . |
@iritkatriel Doesn't this need to be the same in both asynccontextmanager and AsyncExitStack? indeed it do: import contextlib
@contextlib.asynccontextmanager
async def f():
try:
yield
finally:
pass
async def amain():
async with f(): 1/0
with contextlib.closing(amain().__await__()) as gen:
next(gen, None)
|
This breaks thrift generated python code on Python 3.11. Thrift made sure that all generated python exceptions are immutable because Python3 actually expects all exceptions to be hashable, see https://issues.apache.org/jira/browse/THRIFT-4002 and apache/thrift#1835 for more context. Since exceptions are immutable, trying to modify the traceback will cause runtime errors (see https://github.com/reddit/baseplate.py/actions/runs/5205369418/jobs/9390744047 for an example). So is making exceptions immutable wrong? |
@fishy There is no need for the |
we did override both |
Bug report
See HypothesisWorks/hypothesis#3298 trackstack includes
__exit__
incontextlib
which is not the case in previous python versions. Wonder is this intentional and will it be cleaned up when released?Your environment
Also looping @Zac-HD in
The text was updated successfully, but these errors were encountered: