From b1cb67c743de2581f9393315b23777011c22ecf7 Mon Sep 17 00:00:00 2001 From: Nick Douma Date: Thu, 27 Apr 2017 11:44:56 +0200 Subject: 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 --- setuptools/monkey.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'setuptools/monkey.py') diff --git a/setuptools/monkey.py b/setuptools/monkey.py index 68fad9dd..97ba159d 100644 --- a/setuptools/monkey.py +++ b/setuptools/monkey.py @@ -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): lookup = ( get_unpatched_class if isinstance(item, six.class_types) else @@ -38,7 +51,7 @@ def get_unpatched_class(cls): """ external_bases = ( cls - for cls in inspect.getmro(cls) + for cls in get_mro(cls) if not cls.__module__.startswith('setuptools') ) base = next(external_bases) -- cgit v1.2.1 From 8219fe5211aebbc8de8da9c988cc2a2b85b92829 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 27 Apr 2017 15:28:54 -0400 Subject: Make _get_mro private; Swap logic to put preferred behavior at top level; Update docstring to reference issue. --- setuptools/monkey.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'setuptools/monkey.py') diff --git a/setuptools/monkey.py b/setuptools/monkey.py index 97ba159d..acd0a4f4 100644 --- a/setuptools/monkey.py +++ b/setuptools/monkey.py @@ -21,17 +21,18 @@ if you think you need this functionality. """ -def get_mro(cls): - """Returns the bases classes for cls sorted by the MRO. +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__ . + of cls.__bases__. See https://github.com/pypa/setuptools/issues/1024. """ - if platform.python_implementation() != "Jython": - return inspect.getmro(cls) - return (cls,) + cls.__bases__ + if platform.python_implementation() == "Jython": + return (cls,) + cls.__bases__ + return inspect.getmro(cls) def get_unpatched(item): @@ -51,7 +52,7 @@ def get_unpatched_class(cls): """ external_bases = ( cls - for cls in get_mro(cls) + for cls in _get_mro(cls) if not cls.__module__.startswith('setuptools') ) base = next(external_bases) -- cgit v1.2.1