You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
fromtypingimportContextManagerclassA(ContextManager[int]):
__slots__= ()
__enter__=__exit__=lambda*args: NoneA().a=1# No exception
Changing ContextManager to MutableMapping, for example (and setting relevant dunders), does raise an exception.
Activity
sunmy2019 commentedon Jun 13, 2023
Indeed, can you open a PR for that?
erezinman commentedon Jun 13, 2023
@sunmy2019
Yeah, I'll try to get to that later. To which branch?
sunmy2019 commentedon Jun 13, 2023
Changes like this are considered new features. So
mainfix python#105726
fix python#105726
gh-105726: Add `__slots__` to `AbstractContextManager` and `AbstractA…
sobolevn commentedon Jul 16, 2023
@grigoriev-semyon thank you!