summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-21 19:45:08 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-21 19:45:08 (GMT)
commit095fb84fc2cab3c01e6b6b6862a8e263f934779b (patch)
tree109444634949485775b95cddc7c755cf9379d38e /Lib
parentc9745e5f7d98b0f9a0cb1edc805b924fe1d5a473 (diff)
parentbf341fb5f6016ca5c79cee01211631ab5a01c5cf (diff)
downloadcpython-095fb84fc2cab3c01e6b6b6862a8e263f934779b.zip
cpython-095fb84fc2cab3c01e6b6b6862a8e263f934779b.tar.gz
cpython-095fb84fc2cab3c01e6b6b6862a8e263f934779b.tar.bz2
Issue 23898: Fix inspect.classify_class_attrs() to work with __eq__
Patch by Mike Bayer.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/inspect.py6
-rw-r--r--Lib/test/test_inspect.py15
2 files changed, 18 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 19b57b4..4aa95da 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -395,7 +395,7 @@ def classify_class_attrs(cls):
# first look in the classes
for srch_cls in class_bases:
srch_obj = getattr(srch_cls, name, None)
- if srch_obj == get_obj:
+ if srch_obj is get_obj:
last_cls = srch_cls
# then check the metaclasses
for srch_cls in metamro:
@@ -403,7 +403,7 @@ def classify_class_attrs(cls):
srch_obj = srch_cls.__getattr__(cls, name)
except AttributeError:
continue
- if srch_obj == get_obj:
+ if srch_obj is get_obj:
last_cls = srch_cls
if last_cls is not None:
homecls = last_cls
@@ -417,7 +417,7 @@ def classify_class_attrs(cls):
# unable to locate the attribute anywhere, most likely due to
# buggy custom __dir__; discard and move on
continue
- obj = get_obj or dict_obj
+ obj = get_obj if get_obj is not None else dict_obj
# Classify the object or its descriptor.
if isinstance(dict_obj, staticmethod):
kind = "static method"
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index a4add38..44405ee 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -888,6 +888,21 @@ class TestClassesAndFunctions(unittest.TestCase):
should_find_ga = inspect.Attribute('ham', 'data', Meta, 'spam')
self.assertIn(should_find_ga, inspect.classify_class_attrs(VA))
+ def test_classify_overrides_bool(self):
+ class NoBool(object):
+ def __eq__(self, other):
+ return NoBool()
+
+ def __bool__(self):
+ raise NotImplementedError(
+ "This object does not specify a boolean value")
+
+ class HasNB(object):
+ dd = NoBool()
+
+ should_find_attr = inspect.Attribute('dd', 'data', HasNB, HasNB.dd)
+ self.assertIn(should_find_attr, inspect.classify_class_attrs(HasNB))
+
def test_classify_metaclass_class_attribute(self):
class Meta(type):
fish = 'slap'