Skip to content

Commit

Permalink
Use inspect.getmro to inspect the mro. Alternate implementation to th…
Browse files Browse the repository at this point in the history
…at proposed in #1092.
  • Loading branch information
jaraco committed Jul 26, 2017
1 parent c452f9f commit 35fa31f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v36.2.4
-------

* #1092: ``pkg_resources`` now uses ``inspect.getmro`` to
resolve classes in method resolution order.

v36.2.3
-------

Expand Down
21 changes: 11 additions & 10 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tempfile
import textwrap
import itertools
import inspect
from pkgutil import get_importer

try:
Expand Down Expand Up @@ -2939,20 +2940,20 @@ def parse(s):
return req


def _get_mro(cls):
"""Get an mro for a type or classic class"""
if not isinstance(cls, type):

class cls(cls, object):
pass

return cls.__mro__[1:]
return cls.__mro__
def _always_object(classes):
"""
Ensure object appears in the mro even
for old-style classes.
"""
if object not in classes:
return classes + (object,)
return classes


def _find_adapter(registry, ob):
"""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:
return registry[t]

Expand Down

0 comments on commit 35fa31f

Please sign in to comment.