Commit b1cb67c7 authored by Nick Douma's avatar Nick Douma

Use a different method to lookup base classes on Jython

Jython seems to implement inspect.getmro differently, which causes
any classes with the same name as a class lower in the MRO not to
be returned.

This patch offloads the MRO lookup to a separate function, which
implements different logic for Jython only.

Ref #1024
parent d8e1ed57
...@@ -21,6 +21,19 @@ if you think you need this functionality. ...@@ -21,6 +21,19 @@ if you think you need this functionality.
""" """
def get_mro(cls):
"""Returns the bases classes for cls sorted by the MRO.
Works around an issue on Jython where inspect.getmro will not return all
base classes if multiple classes share the same name. Instead, this
function will return a tuple containing the class itself, and the contents
of cls.__bases__ .
"""
if platform.python_implementation() != "Jython":
return inspect.getmro(cls)
return (cls,) + cls.__bases__
def get_unpatched(item): def get_unpatched(item):
lookup = ( lookup = (
get_unpatched_class if isinstance(item, six.class_types) else get_unpatched_class if isinstance(item, six.class_types) else
...@@ -38,7 +51,7 @@ def get_unpatched_class(cls): ...@@ -38,7 +51,7 @@ def get_unpatched_class(cls):
""" """
external_bases = ( external_bases = (
cls cls
for cls in inspect.getmro(cls) for cls in get_mro(cls)
if not cls.__module__.startswith('setuptools') if not cls.__module__.startswith('setuptools')
) )
base = next(external_bases) base = next(external_bases)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment