Re: Question regarding unexpected behavior in using __enter__ method

2023-04-26 Thread Mark Bourne
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 ...

RE: Question regarding unexpected behavior in using __enter__ method

2023-04-25 Thread avi.e.gross
ans 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

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-25 Thread Rob Cliffe via Python-list
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

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-21 Thread aapost
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

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-21 Thread Lorenzo Catoni
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

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-21 Thread Peter Otten
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: ...

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-20 Thread Cameron Simpson
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__ =

Re: Question regarding unexpected behavior in using __enter__ method

2023-04-20 Thread dn via Python-list
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