On 3/26/22 09:57, malmiteria wrote:

> The core of what i wanna discuss here is that i don't think mro and super (mainly because it relies on mro) are very pythonic. Mainly that some behaviors of the mro are too implicit, and are silencing what really should be errors.

When I first started using Python I also didn't like super() and the mro. However, at some point it dawned on me that subclassing is not a trivial task -- you don't just get a new class with some neat behavior from another class -- what you get is the original class, plus some neat behavior from the new class. In other words, subclassing is a very tight coupling of code, and you had better know the classes you are inheriting from to get it right -- and that part is the programmer's responsibility, not Python's.

To use your `run()` example:

    class A:
        def run(self):
            print('A')

    class B:
        def run(self):
            print('B')


    class Z(A, B):

        def run(self):
            # make the programmer choose
            raise RuntimeError("call to `run()` not allowed, choose `run_a()` or 
`run_b()`")

        def run_a(self):
            return A.run()

        def run_b(self):
            return B.run()

--
~Ethan~
_______________________________________________
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/EVCUL3PVRIDAMMRYGU56J4AK4ZBRNM64/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to