On Thu, Feb 18, 2021 at 1:59 PM Ben Rudiak-Gould <benrud...@gmail.com> wrote:
>
> On Wed, Feb 17, 2021 at 6:12 PM Chris Angelico <ros...@gmail.com> wrote:
>>
>> But if object() could get arbitrary attributes, then __slots__ wouldn't work.
>
>
> It seems to me that all you'd have to do is add a line or two to the add_dict 
> logic in type_new so that instances of object get a dict. Then instances of 
> object would get a dict, and nothing else would change.
>
> In languages like C++ where an instance of a class contains actual in-memory 
> instances of all of its superclasses, that wouldn't work. In Python, where 
> instances of different classes have a priori nothing to do with each other, I 
> think it would work.
>

Even if it's possible, though, it's a fairly significant breach of
Liskov. And I don't know that other Python implementations would be
able to do this so cleanly.

What's so hard about using a different type? Especially since the
vanilla object repr is basically useless, but SimpleNamespace can tell
you what it's carrying.

Orthogonal point: SimpleNamespace could easily be made
JSON-serializable (as a dict), if that would be of value.

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

Reply via email to