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
functools.singledispatch fails when "not BaseClass" is True #67760
Comments
I admit this case is rather convoluted, but I have been debugging a few hours so I think I should share my findings. I have a metaclass MetaA that provides to the classes constructed with it have a dictionary interface. Of all the functions only __len__ is important. In some cases, the result of __len__ is 0 and that is what triggers the error class MetaA(type):
def __len__(self):
return 0
class A(metaclass=MetaA):
pass
class AA(A):
pass Now, I construct a function with single dispatch and register the case of class A but not the class AA @singledispatch
def fun(a):
print('base case')
@fun.register(A)
def _(a):
print('fun A') And then, call fun with an object of class AA fun(AA()) This should call the function for the class up in the hierarchy, A RuntimeError: Inconsistent hierarchy in function functools._c3_merge if not candidate:
raise RuntimeError("Inconsistent hierarchy") "not candidate" evaluates to True due to __len__ returning 0 This can be avoided by:
I'm not really sure, but instead of: if not candidate:
raise RuntimeError("Inconsistent hierarchy") would this work? if candidate is None:
raise RuntimeError("Inconsistent hierarchy") I attach a test case |
Yes, this needs addressing. |
An example is Enum. |
Attached is patch and test case. |
I was also bitten by this via Enum. Is there any chance this will be fixed in Python 3.5? |
New changeset 73984e665bf5 by Yury Selivanov in branch '3.5': New changeset 94d0c219d46f by Yury Selivanov in branch 'default': |
It will be fixed in 3.5.1. Thanks for the patch, Ethan! |
New changeset 586195685aaf by Yury Selivanov in branch '3.4': |
Thank you for fixing this and sorry for not being responsive sooner! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: