This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author John Belmonte
Recipients David Hoyes, John Belmonte, jbelmonte, njs
Date 2021-07-12.06:31:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626071517.17.0.185817733303.issue44594@roundup.psfhosted.org>
In-reply-to
Content
To clarify the problem case, I believe the discrepancy is seen when raising exceptions as follows:

exc = foo()
try:
    raise exc
finally:
    exc.__context__ = None

(From my understanding, Trio has valid use cases for doing this since it wants to control complex exception chaining, and this is beyond the scope of __suppress_context__.)

Neither ExitStack nor AsyncExcitStack are preserving the None context in the case above.

  === `with` statement ===
  Traceback (most recent call last):
    File "exit_stack_test.py", line 251, in <module>
      assert False
    File "/.../python3.7/contextlib.py", line 130, in __exit__
      self.gen.throw(type, value, traceback)
    File "exit_stack_test.py", line 244, in my_cm
      raise exc
  MyException

  === enter_context() ===
  Traceback (most recent call last):
    File "exit_stack_test.py", line 240, in my_cm
      yield
    File "exit_stack_test.py", line 259, in <module>
      assert False
  AssertionError

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "exit_stack_test.py", line 259, in <module>
      assert False
    File "/.../python3.7/contextlib.py", line 524, in __exit__
      raise exc_details[1]
    File "/.../python3.7/contextlib.py", line 509, in __exit__
      if cb(*exc_details):
    File "/.../python3.7/contextlib.py", line 377, in _exit_wrapper
      return cm_exit(cm, exc_type, exc, tb)
    File "/.../python3.7/contextlib.py", line 130, in __exit__
      self.gen.throw(type, value, traceback)
    File "exit_stack_test.py", line 244, in my_cm
      raise exc
  MyException
History
Date User Action Args
2021-07-12 06:31:57John Belmontesetrecipients: + John Belmonte, jbelmonte, njs, David Hoyes
2021-07-12 06:31:57John Belmontesetmessageid: <1626071517.17.0.185817733303.issue44594@roundup.psfhosted.org>
2021-07-12 06:31:57John Belmontelinkissue44594 messages
2021-07-12 06:31:57John Belmontecreate