-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
contextlib.ContextManager doesn't contain __slots__ = () #105726
Copy link
Copy link
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
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 exceptionChanging ContextManager to MutableMapping, for example (and setting relevant dunders), does raise an exception.
Observed on Ubuntu 20.04 and Python 3.9.16.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error