Commit 35fa31fa authored by Jason R. Coombs's avatar Jason R. Coombs

Use inspect.getmro to inspect the mro. Alternate implementation to that proposed in #1092.

parent c452f9fd
v36.2.4
-------
* #1092: ``pkg_resources`` now uses ``inspect.getmro`` to
resolve classes in method resolution order.
v36.2.3 v36.2.3
------- -------
......
...@@ -37,6 +37,7 @@ import email.parser ...@@ -37,6 +37,7 @@ import email.parser
import tempfile import tempfile
import textwrap import textwrap
import itertools import itertools
import inspect
from pkgutil import get_importer from pkgutil import get_importer
try: try:
...@@ -2939,20 +2940,20 @@ class Requirement(packaging.requirements.Requirement): ...@@ -2939,20 +2940,20 @@ class Requirement(packaging.requirements.Requirement):
return req return req
def _get_mro(cls): def _always_object(classes):
"""Get an mro for a type or classic class""" """
if not isinstance(cls, type): Ensure object appears in the mro even
for old-style classes.
class cls(cls, object): """
pass if object not in classes:
return classes + (object,)
return cls.__mro__[1:] return classes
return cls.__mro__
def _find_adapter(registry, ob): def _find_adapter(registry, ob):
"""Return an adapter factory for `ob` from `registry`""" """Return an adapter factory for `ob` from `registry`"""
for t in _get_mro(getattr(ob, '__class__', type(ob))): types = _always_object(inspect.getmro(getattr(ob, '__class__', type(ob))))
for t in types:
if t in registry: if t in registry:
return registry[t] return registry[t]
......
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