Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contextlib.ContextManager doesn't contain __slots__ = () #105726

Closed
erezinman opened this issue Jun 13, 2023 · 4 comments
Closed

contextlib.ContextManager doesn't contain __slots__ = () #105726

erezinman opened this issue Jun 13, 2023 · 4 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@erezinman
Copy link

erezinman commented Jun 13, 2023

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.

Linked PRs

@erezinman erezinman added the type-bug An unexpected behavior, bug, or error label Jun 13, 2023
@sunmy2019
Copy link
Member

Indeed, can you open a PR for that?

@erezinman
Copy link
Author

@sunmy2019
Yeah, I'll try to get to that later. To which branch?

@sunmy2019
Copy link
Member

Changes like this are considered new features. So main

grigoriev-semyon added a commit to grigoriev-semyon/cpython that referenced this issue Jul 15, 2023
grigoriev-semyon added a commit to grigoriev-semyon/cpython that referenced this issue Jul 15, 2023
kumaraditya303 added a commit that referenced this issue Jul 16, 2023
…syncContextManager` (#106771)

Co-authored-by: Kumar Aditya <[email protected]>
@sobolevn
Copy link
Member

@grigoriev-semyon thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants