Closed
Description
Python's ABCs should have __slots__
attributes to not interfere with slotting in derived classes (especially when the class has no members). However, it is not the case for contextlib.ContextManager
(as for other contextlib
ABCs):
from typing import ContextManager
class A(ContextManager[int]):
__slots__ = ()
__enter__ = __exit__ = lambda *args: None
A().a = 1 # No exception
Changing ContextManager
to MutableMapping
, for example (and setting relevant dunders), does raise an exception.
Observed on Ubuntu 20.04 and Python 3.9.16.