[Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

Ivan Levkivskyi levkivskyi at gmail.com
Wed May 17 17:29:25 EDT 2017


On 17 May 2017 at 20:09, Sven R. Kunze <srkunze at mail.de> wrote:

> Hi Stephan,
>
> On 17.05.2017 08:49, Stephan Houben wrote:
>
>> 2. Not subclassed from tuple. I have been bitten by this subclassing
>> when trying to set up
>>     singledispatch on sequences and also on my classes.
>>
>
> Would it make sense to have a 'simpleobject'? Which basically implements a
> NamedTuple constructor but nothing more?
>
> class Foo(simpleobject):
>     attribute1: User
>     attribute2: Blog
>     attribute3: list
>
>
> And if you need more __dunder__ magic, have it provided by some mixins?
>
>
> class Foo(dictlike, tuplelike, simpleobject):
>     attribute1: User
>     attribute2: Blog
>     attribute3: list
>
>      def __my_dunder__(self):
>         ...
>

As I understand this is more or less what is proposed, the idea is to write
it into a PEP and consider API/corner cases/implementation/etc.

--
Ivan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170517/b29bdadf/attachment.html>


More information about the Python-ideas mailing list