diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2017-07-26 13:07:38 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-07-26 13:07:38 -0400 |
| commit | 35fa31fa6705d6b6866b5f5361b833e19339713b (patch) | |
| tree | 979243c4ca9782b7a1f37de32cbbf0daebe4ecf1 /pkg_resources | |
| parent | c452f9fdd87d990fb81f7e48d6cb0fe1fcd4b92e (diff) | |
| download | python-setuptools-git-35fa31fa6705d6b6866b5f5361b833e19339713b.tar.gz | |
Use inspect.getmro to inspect the mro. Alternate implementation to that proposed in #1092.
Diffstat (limited to 'pkg_resources')
| -rw-r--r-- | pkg_resources/__init__.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 51b47492..f6666968 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -37,6 +37,7 @@ import email.parser import tempfile import textwrap import itertools +import inspect from pkgutil import get_importer try: @@ -2939,20 +2940,20 @@ class Requirement(packaging.requirements.Requirement): 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] |
