bpo-30266: support "= None" pattern in AbstractContextManager (#1448)

contextlib.AbstractContextManager now supports anti-registration
by setting __enter__ = None or __exit__ = None, following the pattern
introduced in bpo-25958.
This commit is contained in:
Jelle Zijlstra 2017-06-09 08:21:47 -07:00 committed by Guido van Rossum
parent 3b5cf85edc
commit 57161aac5e
3 changed files with 16 additions and 3 deletions

View file

@ -44,6 +44,16 @@ class TestAbstractContextManager(unittest.TestCase):
self.assertTrue(issubclass(DefaultEnter, AbstractContextManager))
class NoEnter(ManagerFromScratch):
__enter__ = None
self.assertFalse(issubclass(NoEnter, AbstractContextManager))
class NoExit(ManagerFromScratch):
__exit__ = None
self.assertFalse(issubclass(NoExit, AbstractContextManager))
class ContextManagerTestCase(unittest.TestCase):