On Sat, Jun 22, 2019 at 11:19 AM nate lust <natel...@linux.com> wrote:
> Typing this out though does make me think of an interesting idea. If there 
> was something like __getself__ in addition to __setself__, you could 
> implement things like MyInt. __getself__ would look something like:
>
> class MyInt:
>     def __init__(self, value):
>         self.value = value
>     def __getself__(self):
>         return self.value
>     def __setself__(self, value):
>         raise ValueError("Cant set MyInt")
> x = MyInt(2)
> print(x) -> 2
> type(x) -> MyInt
>
> Now I have not really thought through how this would work, if it could work...

How does print know to call getself, but type know not to?

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/3734V62OHMJN3736PKWQ7IZ533TPM23J/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to