diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2017-06-09 15:21:47 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2017-06-09 15:21:47 (GMT) |
commit | 57161aac5eb9bcb0b43e551a1937ff0a84c1ec52 (patch) | |
tree | 04296787a6bbf099a38d2b24ac91fc0c83a8e7df /Lib/contextlib.py | |
parent | 3b5cf85edc188345668f987c824a2acb338a7816 (diff) | |
download | cpython-57161aac5eb9bcb0b43e551a1937ff0a84c1ec52.zip cpython-57161aac5eb9bcb0b43e551a1937ff0a84c1ec52.tar.gz cpython-57161aac5eb9bcb0b43e551a1937ff0a84c1ec52.tar.bz2 |
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.
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r-- | Lib/contextlib.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py index c53b35e..962ceda 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -1,6 +1,7 @@ """Utilities for with-statement contexts. See PEP 343.""" import abc import sys +import _collections_abc from collections import deque from functools import wraps @@ -25,9 +26,7 @@ class AbstractContextManager(abc.ABC): @classmethod def __subclasshook__(cls, C): if cls is AbstractContextManager: - if (any("__enter__" in B.__dict__ for B in C.__mro__) and - any("__exit__" in B.__dict__ for B in C.__mro__)): - return True + return _collections_abc._check_methods(C, "__enter__", "__exit__") return NotImplemented |