contextlib: Remove explicit base class from ExitStack (#7963)

Fixes #7961
This commit is contained in:
Jelle Zijlstra
2022-05-27 09:19:18 -07:00
committed by GitHub
parent 2d2b34c1ee
commit c35ec8ba89
2 changed files with 20 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
from contextlib import ExitStack
from typing_extensions import assert_type
# See issue #7961
class Thing(ExitStack):
pass
stack = ExitStack()
thing = Thing()
assert_type(stack.enter_context(Thing()), Thing)
assert_type(thing.enter_context(ExitStack()), ExitStack)
with stack as cm:
assert_type(cm, ExitStack)
with thing as cm2:
assert_type(cm2, Thing)