Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NodeMixin - TypeError: multiple bases have instance lay-out conflict #77

Closed
bakert opened this issue Feb 17, 2019 · 7 comments
Closed
Milestone

Comments

@bakert
Copy link

bakert commented Feb 17, 2019

Works: 2.4.3
Breaks: 2.6.0

>>> from munch import Munch
>>> from anytree import NodeMixin
>>> class MyClass(Munch, NodeMixin):
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict

Where munch is https://github.com/Infinidat/munch

Googling around a bit this seems to be about conflicts in C implementations of classes on __foo__ attributes. So I did this:

>>> [k for k in dir(Munch) if k in dir(NodeMixin)]
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

but it didn't make me feel much smarter.

Does this mean anything to you anytree peeps? I came here because obviously NodeMixin is meant to be mixed in so this feels like a bug rather than just a stupid thing I should not be attempting to do. Especially as it used to work until this version.

@bakert
Copy link
Author

bakert commented Feb 19, 2019

The Munch folks believe that it's probably because Munch derives from dict which uses __slots__. Does NodeMixin now use __slots__?

@c0fec0de
Copy link
Owner

c0fec0de commented Feb 19, 2019

Yes. __slots__ has been added. Please try:

>>> from munch import Munch
>>> from anytree import NodeMixin
>>> class MyNodeMixin(NodeMixin):
...     pass
>>> class MyClass(Munch, MyNodeMixin):
...     pass

As __slots__ is not inherited, it might work

@bakert
Copy link
Author

bakert commented Feb 20, 2019

Thanks for taking a look. Sadly the above code gives the same error.

[gaghalfrunt pd] python3
Python 3.7.1 (default, Nov 28 2018, 11:51:47) 
[Clang 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from munch import Munch
>>> from anytree import NodeMixin
>>> class MyNodeMixin(NodeMixin):
...     pass
... 
>>> class MyClass(Munch, MyNodeMixin):
...     pass
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: multiple bases have instance lay-out conflict

@bakert
Copy link
Author

bakert commented Feb 20, 2019

Reading up at https://stackoverflow.com/questions/472000/usage-of-slots and https://docs.python.org/3/reference/datamodel.html#notes-on-using-slots it sounds like including __slots__ in something designed to be inherited from/mixed in might be something you want to revisit? I'm a total ignoramus so I'm all ears if you have any ideas other than freezing the anytree version at 2.4.3. Thanks!

@jkbgbr
Copy link
Contributor

jkbgbr commented Feb 20, 2019 via email

@c0fec0de
Copy link
Owner

I am not sure yet, which is the best way to go. Leave __slots__ or remove.

@c0fec0de
Copy link
Owner

slots will be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants