[Python-ideas] Re: An interface for `mro` methods similar to the interface for `iter`, `getattr`, etc...
On 24/03/2023 17:30, Samuel Muldoon wrote: *Additionally, the class named `object` should have a method named `__mro__` and any class which inherits from `object` may override `__mro__` or inherit the default `* *object* *.__mro__` . * It already has an attribute of that name: >>> object.__mro__ (,) Best wishes Rob Cliffe___ 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/TRU2ZCVED2NKMLFIFBIKNLKJW7LAC4HJ/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Re: An interface for `mro` methods similar to the interface for `iter`, `getattr`, etc...
Hi Samuel, Classes already have a `obj.mro()` public method that wraps their private dunder `__mro__`. Non-classes (instances) don't have a `__mro__`. > Additionally, the class named `object` should have a method named > `__mro__` and any class which inherits from `object` may override > `__mro__` or inherit the default `object.__mro__`. Guido's time machine strikes again. This has existed since Python 2.2 or thereabouts, so more than twenty years ago: >>> object.__mro__ (,) >>> object.mro() [] -- Steve ___ 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/ZYGLKVXQKWJX3KHNZGIJRGRXJBJBGIP4/ Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] An interface for `mro` methods similar to the interface for `iter`, `getattr`, etc...
*Greetings Fellow Earthlings,* *In python 3.11, python has a number of built-in functions which act as an Interface for magic dunder methods. Two examples of what I am talking about are shown below: * *Begin Example 1 of 2* *rocky = object()x = getattr(rocky, "length") x = rocky.__getattr__("length") * *Begin Example 2 of 2* *box = [1, 2, 3]it = iter(box) it = box.__iter__()* *My suggestion is that in future versions of python, we will have `mro()` behave in a similar fashion. * *obj = object()x = mro(obj) x = obj.__mro__() * *Additionally, the class named `object` should have a method named `__mro__` and any class which inherits from `object` may override `__mro__` or inherit the default `* *object* *.__mro__` . * *Samuel Muldoon* *(720) 653 -2408* *muldoonsam...@gmail.com * ___ 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/IAGPFNRN5BQ2MFIIBCW5PSKQKDB7LWKB/ Code of Conduct: http://python.org/psf/codeofconduct/