Good to hear from you, Serhiy. I hope you and your family are safe.

On Sat, Mar 5, 2022 at 1:29 AM Serhiy Storchaka <storch...@gmail.com> wrote:

> Currently the class can inherit from arbitrary objects, not only types.
> If the object was not designed for this you can get a mysterious
> mistake, e g.:
>
>  >>> class A(1): ...
> ...
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: int() takes at most 2 arguments (3 given)
>
> If the object's constructor is compatible with type constructor by
> accident you can an unexpected result. To prevent this we usually add an
> explicit __mro_entries__() method which raises an exception.
>
> I propose to make __mro_entries__() mandatory if a base is not a type
> instance (with a deprecation period).
>

Funny, I was just thinking about this (reviewing Brett's draft for the next
installment of his desugaring Python blog).

How common is it that people get confused by an error message like from
`class A(1)`? I'm not sure that it's common enough to weigh down the
esoteric use cases (inheriting from non-class objects) with more API.

To me the weirder exception around this is that if a base class *is* a
class object, even if it has a __mro_entries__ method that isn't called. If
we added a __mro_entries__ to type (returning (self,)) it might make more
sense to insist on bases always having a __mro_entries__ method.

Then again I find the name __mro_entries__ somewhat poorly chosen, since it
really is a hook to override the list of explicit bases (i.e., (B, C) for
class A(B, C)), not the MRO (which would be at least (A, B, C, object), and
more if A and/or B have other superclasses).

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/AEVZEBG5K7BY3V3L4MGNFHWXQKYOOPAX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to