On Fri, Jun 28, 2019 at 6:36 AM Steven D'Aprano <st...@pearwood.info> wrote:
>
> On Fri, Jun 28, 2019 at 03:59:14AM +1000, Chris Angelico wrote:
>
> > > Are we talking past each other?
> > >
> >
> > Without any magic, merely attempting to return the wrapper would cause
> > it to collapse to the underlying object (by calling getself).
>
> Yeah, definitely talking past each other.
>
> Let's get concrete:
>
> class Spam:
>     def __getself__(self):
>         print("I can has side-effects!!!")
>         return self
>
> x = Spam()
> x  # Calls __getself__
>
> What are you calling "the wrapper" and "the underlying object"?
>

It's a distinction that doesn't exist in your example, because you
return self. Consider instead:

class Spam:
    def __getself__(self):
        print("I can has side-effects!!!")
        return 42

x = Spam()
x  # Calls __getself__

The wrapper is the instance of Spam, and the underlying object is the
integer 42. Which of these will trigger the print call and work with
42, and which will use the Spam object?

print(x) # 1
y = x # 2
x.numerator # 3
def f(q): return 7 # 4.1
f(x) # 4.1
def g(q): return q # 5.1
g(x) # 5.2

Quite frankly, I can't be sure.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UOBR6VVAHJ35BKPSEBAQL6AUOYCWYSR5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to