[Python-ideas] Override dict.__new__ to raise if cls is not dict; do the same for str, list, etc.

Michael Selik mike at selik.org
Thu Apr 21 07:44:00 EDT 2016


On Thu, Apr 21, 2016 at 7:30 AM Steven D'Aprano <steve at pearwood.info> wrote:

> On Thu, Apr 21, 2016 at 04:36:54PM +1000, Nick Coghlan wrote:
>
> > Builtins can be extended, you just have to override all the methods where
> > you want to change the return type:
>
> I wonder whether we should have a class decorator which automatically
> adds the appropriate methods?
>

If I'm not mistaken, some of the dunders need to be overridden as part of
the class definition and can't be added dynamically without some exec a la
namedtuple. If so, are you still interested in creating that decorator?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160421/f44ffbc1/attachment-0001.html>


More information about the Python-ideas mailing list