[Python-Dev] Possible undefined behavior on creating a method named "__dict__"
On Wed, Apr 11, 2018 at 5:08 AM, Steven D'Aprano <steve at pearwood.info>
> On Wed, Apr 11, 2018 at 08:21:01AM -0300, Joao S. O. Bueno wrote:
> > I just came across a code snippet that
> > would define a method with the "__dict__" name - like in:
> > class A:
> > def __dict__(self):
> > return ()
> That's a strange thing to do, but I don't think it ought to be illegal.
> Consenting adults and all that.
Python's guarantee in this case goes no further than that it promises not
to crash in C code. There's a rule in the language reference that says that
all __dunder__ names are reserved for the implementation and they should
only be used according to the documentation. So, indeed, it's not illegal,
but you are not guaranteed that anything works, either.
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...