[Python-Dev] Make __mro_entries__ mandatory for non-types

2022年3月05日 01:33:28 -0800

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).
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/QDFG65U5ILB7LISC7UL2WFGQIAL2DMUV/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to