It probably doesn't, this was just something I typed up on the fly, so is unlikely the end result would be what you see above if it was actually implemented. The only way around that that I can think of now would be if there was two functions, an impl_dictget that actually did the lookup that type could use (and possibly getattr and the like) which would be called in the normal dict get which would just return if the type did not define __getself__ and would call it and return the result if it did. This is not at all dissimilar to how dict setting works now On Fri, Jun 21, 2019, 9:27 PM Chris Angelico <rosuav@gmail.com> wrote:
Typing this out though does make me think of an interesting idea. If
On Sat, Jun 22, 2019 at 11:19 AM nate lust <natelust@linux.com> wrote: 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-leave@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/3734V6... Code of Conduct: http://python.org/psf/codeofconduct/