On Sat, Nov 18, 2017 at 9:29 PM Nick Coghlan <ncogh...@gmail.com> wrote:

> On 19 November 2017 at 06:56, Neil Girdhar <mistersh...@gmail.com> wrote:
> > Would you mind explaining why it's necessary for C3 to complain?
> >
> > In:
> >
> > S < C
> > B < S, E
> > R < E, C
> > Z < B, R
> >
> > If Z is told to have MRO:
> >
> > (Z, B, S, R, E, C)
> >
> > then there are no conflicts with any base classes.
>
> I don't actually know what C3 allows in principle, I only know that
> CPython's resolver still complains in practice:
>
>     >>> class C: pass
>     ...
>     >>> class S(C): pass
>     ...
>     >>> class E: pass
>     ...
>     >>> class B(S, E): pass
>     ...
>     >>> class R(E, C): pass
>     ...
>     >>> class Z(B, S, R, E, C): pass
>     ...
>     Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>     TypeError: Cannot create a consistent method resolution order
> (MRO) for bases C, E
>
> I think the problem is that the resolver isn't looking at the declared
> bases of "B", and "R", it's looking at their full MRO:
>
>     >>> B.__mro__
>     (<class '__main__.B'>, <class '__main__.S'>, <class '__main__.C'>,
> <class '__main__.E'>, <class 'object'>)
>     >>> R.__mro__
>     (<class '__main__.R'>, <class '__main__.E'>, <class '__main__.C'>,
> <class 'object'>)
>
> Changing the heuristics used to generate B's MRO such that "C" and "E"
> appeared in the opposite order wouldn't really help, since that would
> just flip the problematic case to be the "R(C, E)" declaration.
>

Sorry, I wrote back too quickly.  I meant also to change B's requested MRO
to be:

(B, S, E, C)

It works with that change.


>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to