Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Behavioral differences between the with-statement andExitStack.enter_context #144386

Open
Assignees
serhiy-storchaka
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@gottadiveintopython

Description

@gottadiveintopython

Bug report

Bug description:

I noticed a behavioral difference between the (async) with statement and(Async)ExitStack. The with statement correctly recognizes context manager methods (__enter__,__exit__,__aenter__, and__aexit__) even when they are defined via__slots__, whereas(Async)ExitStack does not.

classSlotsCM:__slots__= ("__enter__","__exit__", )def__init__(self):self.__enter__=self.__exit__=lambda*__:None# This workswithSlotsCM():pass# This doesn't.fromcontextllibimportExitStackwithExitStack()asstack:stack.enter_context(SlotsCM())
Traceback (most recent call last):  File "xxxx.py", line 16, in <module>    stack.enter_context(SlotsCM())    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^  File "......../contextlib.py", line 530, in enter_context    result = _enter(cm)TypeError: 'member_descriptor' object is not callable

Furthermore, both (async) with-statement and(Async)ExitStack don't suppot those special dunder methods stored in__dict__. You can verify from this repository:
https://github.com/gottadiveintopython/invest-context-manager

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Labels

3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2026 Movatter.jp