TypeError: Cannot create a consistent method resolution order (MRO) for bases object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • digitalorganics@gmail.com

    #1

    TypeError: Cannot create a consistent method resolution order (MRO) for bases object

    What are the reason one would get this error: TypeError: Cannot create
    a consistent method resolution order (MRO) for bases object ??

    I can provide the code if needed....

  • Simon Forman

    #2
    Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object

    digitalorganics @gmail.com wrote:[color=blue]
    > What are the reason one would get this error: TypeError: Cannot create
    > a consistent method resolution order (MRO) for bases object ??
    >
    > I can provide the code if needed....[/color]

    Yes, do that.

    That's an amazing error.

    ~Simon

    Comment

    • Terry Reedy

      #3
      Re: TypeError: Cannot create a consistent method resolution order(MRO)for bases object


      <digitalorganic s@gmail.com> wrote in message
      news:1151345197 .691600.200060@ y41g2000cwy.goo glegroups.com.. .[color=blue]
      > What are the reason one would get this error: TypeError: Cannot create
      > a consistent method resolution order (MRO) for bases object ??[/color]

      Because the interpreter cannot ;-)
      [color=blue]
      > I can provide the code if needed....[/color]

      Details beget details ;-)
      Yes, the class statement (header line up to ':') that bombed and the same
      (first line) for classes it inherits from (and their base classes). The
      conflict should be in the latter.

      tjr



      Comment

      • digitalorganics@gmail.com

        #4
        Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object

        Hint: If I change Dog and Bat to old-style classes, there's no problem,
        everything works fine.


        Okay, here's the code dump from my playground::
        ------------------------------------------
        #!/usr/bin/env python

        class Mixin:
        def mixin(object, *classes):
        NewClass = type('Mixin', (object.__class __,) + classes, {})
        newobj = NewClass()
        newobj.__dict__ .update(object. __dict__)
        return newobj

        class Cat(object):
        def __init__(self):
        self.love = 0
        def meow(self):
        print "meow"
        class Dog(object):
        def bark(self):
        print "bark"
        class Bat(object):
        def scream(self):
        print "scream"

        mycat = Cat()
        mycat.love = 4
        mycat.__class__ .__bases__ += (Mixin,)
        mycat.mixin(Dog , Bat)
        print mycat.love

        def isClass(object) :
        if isinstance(obje ct, type):
        return True
        elif isinstance(obje ct, types.ClassType ):
        return True
        else:
        return False

        def listClasses():
        classes = []
        for eachobj in globals().keys( ):
        if isClass(globals ()[eachobj]):
        classes.append( globals()[eachobj])
        print eachobj
        return classes

        def applyMixinGloba l(*Mixins):
        for eachclass in listClasses():
        MixInto(eachcla ss, Mixins)
        #applyMixinGlob al(Mixin)

        def MixInto(Class, *Mixins):
        for eachMixin in Mixins:
        if eachMixin not in Class.__bases__ :
        Class.__bases__ += (eachMixin,)
        MixInto(Bat, Mixin)
        Bat.__bases__ += (Dog,)
        dargo = Bat()
        dargo = dargo.mixin(Cat )
        dargo.meow()

        Simon Forman wrote:[color=blue]
        > digitalorganics @gmail.com wrote:[color=green]
        > > What are the reason one would get this error: TypeError: Cannot create
        > > a consistent method resolution order (MRO) for bases object ??
        > >
        > > I can provide the code if needed....[/color]
        >
        > Yes, do that.
        >
        > That's an amazing error.
        >
        > ~Simon[/color]

        Comment

        • digitalorganics@gmail.com

          #5
          Re: TypeError: Cannot create a consistent method resolution order (MRO)for bases object

          Oh, I forgot the line that bombed, sorry:

          line 52, in __main__
          Bat.__bases__ += (Dog,)
          TypeError: Cannot create a consistent method resolution
          order (MRO) for bases object, Mixin, Dog

          See my other post for the complete code and my relevant note about
          new-style classes, thanks...

          Terry Reedy wrote:[color=blue]
          > <digitalorganic s@gmail.com> wrote in message
          > news:1151345197 .691600.200060@ y41g2000cwy.goo glegroups.com.. .[color=green]
          > > What are the reason one would get this error: TypeError: Cannot create
          > > a consistent method resolution order (MRO) for bases object ??[/color]
          >
          > Because the interpreter cannot ;-)
          >[color=green]
          > > I can provide the code if needed....[/color]
          >
          > Details beget details ;-)
          > Yes, the class statement (header line up to ':') that bombed and the same
          > (first line) for classes it inherits from (and their base classes). The
          > conflict should be in the latter.
          >
          > tjr[/color]

          Comment

          • Maric Michaud

            #6
            Re: TypeError: Cannot create a consistent method resolution order(MRO) for bases object

            Le lundi 26 juin 2006 20:06, digitalorganics @gmail.com a écrit :[color=blue]
            > What are the reason one would get this error: TypeError: Cannot create
            > a consistent method resolution order (MRO) for bases object ??
            >
            > I can provide the code if needed....[/color]
            This is the python solution to the diamond problem (cf. wikipedia).

            In [61]: class a(object) : pass
            ....:
            In [62]: class b(a) : pass
            ....:
            In [63]: class c(object, a) : pass
            ....:
            ---------------------------------------------------------------------------
            exceptions.Type Error Traceback (most recent
            call last)

            /home/maric/<ipython console>

            TypeError: Error when calling the metaclass bases
            Cannot create a consistent method resolution
            order (MRO) for bases object, a

            In [64]: b.mro()
            Out[64]: [<class '__main__.b'>, <class '__main__.a'>, <type 'object'>]

            In [65]: class c(a, object) : pass
            ....:

            In [66]: c.mro()
            Out[66]: [<class '__main__.c'>, <class '__main__.a'>, <type 'object'>]

            In [67]: class d(b, c) : pass
            ....:

            In [69]: d.mro()
            Out[69]:
            [<class '__main__.d'>,
            <class '__main__.b'>,
            <class '__main__.c'>,
            <class '__main__.a'>,
            <type 'object'>]

            mro means "method resolution order", this is the path the interpreter will
            look for attributes for a given class. You cannot introduce inconsistency in
            this path, for example duplicate the type object before another type (or any
            type wich appear to be the ancestor of another).

            --
            _____________

            Maric Michaud
            _____________

            Aristote - www.aristote.info
            3 place des tapis
            69004 Lyon
            Tel: +33 426 880 097

            Comment

            • digitalorganics@gmail.com

              #7
              Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object


              Maric Michaud wrote:[color=blue]
              > Le lundi 26 juin 2006 20:06, digitalorganics @gmail.com a écrit :[color=green]
              > > What are the reason one would get this error: TypeError: Cannot create
              > > a consistent method resolution order (MRO) for bases object ??
              > >
              > > I can provide the code if needed....[/color]
              > This is the python solution to the diamond problem (cf. wikipedia).
              >
              > In [61]: class a(object) : pass
              > ....:
              > In [62]: class b(a) : pass
              > ....:
              > In [63]: class c(object, a) : pass
              > ....:
              > ---------------------------------------------------------------------------
              > exceptions.Type Error Traceback (most recent
              > call last)
              >
              > /home/maric/<ipython console>
              >
              > TypeError: Error when calling the metaclass bases
              > Cannot create a consistent method resolution
              > order (MRO) for bases object, a
              >
              > In [64]: b.mro()
              > Out[64]: [<class '__main__.b'>, <class '__main__.a'>, <type 'object'>]
              >
              > In [65]: class c(a, object) : pass
              > ....:
              >
              > In [66]: c.mro()
              > Out[66]: [<class '__main__.c'>, <class '__main__.a'>, <type 'object'>]
              >
              > In [67]: class d(b, c) : pass
              > ....:
              >
              > In [69]: d.mro()
              > Out[69]:
              > [<class '__main__.d'>,
              > <class '__main__.b'>,
              > <class '__main__.c'>,
              > <class '__main__.a'>,
              > <type 'object'>]
              >
              > mro means "method resolution order", this is the path the interpreter will
              > look for attributes for a given class. You cannot introduce inconsistencyin
              > this path, for example duplicate the type object before another type (or any
              > type wich appear to be the ancestor of another).
              >
              > --[/color]

              Ah, thank you Maric, I see the problem. I diagrammed the flow of class
              inheritance and I can see the problem clearly. Ruby doesn't have this
              problem because it uses a single inheritance model complemented by the
              power of mixins (modules of functionality mixed into classes as
              needed). So what's the Pythonic solution to this problem?

              Comment

              • Steve Holden

                #8
                Re: TypeError: Cannot create a consistent method resolution order(MRO) for bases object

                digitalorganics @gmail.com wrote:[color=blue]
                > Maric Michaud wrote:
                >[color=green]
                >>Le lundi 26 juin 2006 20:06, digitalorganics @gmail.com a écrit :
                >>[color=darkred]
                >>>What are the reason one would get this error: TypeError: Cannot create
                >>>a consistent method resolution order (MRO) for bases object ??
                >>>
                >>>I can provide the code if needed....[/color]
                >>
                >>This is the python solution to the diamond problem (cf. wikipedia).
                >>
                >>In [61]: class a(object) : pass
                >> ....:
                >>In [62]: class b(a) : pass
                >> ....:
                >>In [63]: class c(object, a) : pass
                >> ....:
                >>---------------------------------------------------------------------------
                >>exceptions.Ty peError Traceback (most recent
                >>call last)
                >>
                >>/home/maric/<ipython console>
                >>
                >>TypeError: Error when calling the metaclass bases
                >> Cannot create a consistent method resolution
                >>order (MRO) for bases object, a
                >>
                >>In [64]: b.mro()
                >>Out[64]: [<class '__main__.b'>, <class '__main__.a'>, <type 'object'>]
                >>
                >>In [65]: class c(a, object) : pass
                >> ....:
                >>
                >>In [66]: c.mro()
                >>Out[66]: [<class '__main__.c'>, <class '__main__.a'>, <type 'object'>]
                >>
                >>In [67]: class d(b, c) : pass
                >> ....:
                >>
                >>In [69]: d.mro()
                >>Out[69]:
                >>[<class '__main__.d'>,
                >> <class '__main__.b'>,
                >> <class '__main__.c'>,
                >> <class '__main__.a'>,
                >> <type 'object'>]
                >>
                >>mro means "method resolution order", this is the path the interpreter will
                >>look for attributes for a given class. You cannot introduce inconsistency in
                >>this path, for example duplicate the type object before another type (or any
                >>type wich appear to be the ancestor of another).
                >>
                >>--[/color]
                >
                >
                > Ah, thank you Maric, I see the problem. I diagrammed the flow of class
                > inheritance and I can see the problem clearly. Ruby doesn't have this
                > problem because it uses a single inheritance model complemented by the
                > power of mixins (modules of functionality mixed into classes as
                > needed). So what's the Pythonic solution to this problem?
                >[/color]
                Technically, wait until Python 3.0. Until then, just make sure all your
                classes inherit from (something that inherits from ...) object.

                regards
                Steve
                --
                Steve Holden +44 150 684 7255 +1 800 494 3119
                Holden Web LLC/Ltd http://www.holdenweb.com
                Love me, love my blog http://holdenweb.blogspot.com
                Recent Ramblings http://del.icio.us/steve.holden

                Comment

                • Michele Simionato

                  #9
                  Re: TypeError: Cannot create a consistent method resolution order (MRO) for bases object

                  digitalorganics @gmail.com wrote:[color=blue]
                  > What are the reason one would get this error: TypeError: Cannot create
                  > a consistent method resolution order (MRO) for bases object ??[/color]

                  See http://www.python.org/download/releases/2.3/mro/

                  Michele Simionato

                  Comment

                  Working...