This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients Ilya.Kulakov, giampaolo.rodola, ncoghlan, thehesiod, veky, yselivanov
Date 2017-08-19.16:44:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1503161065.49.0.574543529984.issue29302@psf.upfronthosting.co.za>
In-reply-to
Content
> I'm not sure about type() to get a class object and calling __aenter__, __aexit__ through it: that makes it hard to mock these classes as Mock's spec= relies on __class__ and type() seem to ignore it (learned it a hard way.

Looking up __dunder__ methods on the class is how it should be done as that's how the rest of Python works.  And that's how ExitStack is currently implemented for synchronous "with" blocks.  We won't be able to change this behaviour even if we wanted to, so it stays.

Here's an example:

    class Foo:
        def __init__(self):
            self.__aenter__ = ...
            self.__aexit__ = ...

If we implement AsyncExitStack to lookup __anter__ directly on the object, then the above Foo class would be supported by it, but at the same time rejected by the 'async with' statement.

> Yury, I could take a second look and try to change this into a patch if that's OK.

By all means you can submit a PR!
History
Date User Action Args
2017-08-19 16:44:25yselivanovsetrecipients: + yselivanov, ncoghlan, giampaolo.rodola, thehesiod, veky, Ilya.Kulakov
2017-08-19 16:44:25yselivanovsetmessageid: <1503161065.49.0.574543529984.issue29302@psf.upfronthosting.co.za>
2017-08-19 16:44:25yselivanovlinkissue29302 messages
2017-08-19 16:44:25yselivanovcreate