Lorenzo Catoni wrote:
Dear Python Mailing List members,
I am writing to seek your assistance in understanding an unexpected
behavior that I encountered while using the __enter__ method. I have
provided a code snippet below to illustrate the problem:
```
class X:
... __enter__ = int
...
knowing there will be a first argument.
Avi
-Original Message-
From: Python-list On
Behalf Of Rob Cliffe via Python-list
Sent: Saturday, April 22, 2023 9:56 AM
To: Lorenzo Catoni ; python-list@python.org
Subject: Re: Question regarding unexpected behavior in using __enter__ method
Thi
This puzzled me at first, but I think others have nailed it. It is not
to do with the 'with' statement, but with the way functions are defined.
When a class is instantiated, as in x=X():
the instance object gets (at least in effect), as attributes,
copies of functions defined *in the class*
On 4/20/23 18:44, Lorenzo Catoni wrote:
Here, the TypeError occurred because "self" was passed as an input
Instantiate X and observe it there
x2 = X()
>>> X.__enter__
>>> X.__exit__
at 0x...>
>>> x2.__enter__
>>> x2.__exit__
of <__main__.X object at 0x...>>
To receive self the method mu
Thankyou for your answer,
i think i found the reason for this behavior, is has to do with the
function being user defined or not, rather than being a plain function or
type, as stated here
https://docs.python.org/3/reference/datamodel.html#:~:text=Also%20notice%20that%20this%20transformation%20only
On 21/04/2023 00:44, Lorenzo Catoni wrote:
Dear Python Mailing List members,
I am writing to seek your assistance in understanding an unexpected
behavior that I encountered while using the __enter__ method. I have
provided a code snippet below to illustrate the problem:
```
class X:
... _
On 21Apr2023 00:44, Lorenzo Catoni wrote:
I am writing to seek your assistance in understanding an unexpected
behavior that I encountered while using the __enter__ method. I have
provided a code snippet below to illustrate the problem:
```
class X:
... __enter__ = int
... __exit__ = l
On 21/04/2023 10.44, Lorenzo Catoni wrote:
I am writing to seek your assistance in understanding an unexpected
behavior that I encountered while using the __enter__ method. I have
provided a code snippet below to illustrate the problem:
It is expected behavior - just not what WE might have expe
Dear Python Mailing List members,
I am writing to seek your assistance in understanding an unexpected
behavior that I encountered while using the __enter__ method. I have
provided a code snippet below to illustrate the problem:
```
>>> class X:
... __enter__ = int
... __exit__ = lambda *_