[Python-checkins] cpython (3.4): Issue 23898: Fix inspect.classify_class_attrs() to work with __eq__
yury.selivanov
python-checkins at python.org
Thu May 21 21:46:17 CEST 2015
https://hg.python.org/cpython/rev/fb9addfdfc35
changeset: 96194:fb9addfdfc35
branch: 3.4
parent: 96192:7fa2f4afcf5a
user: Yury Selivanov <yselivanov at sprymix.com>
date: Thu May 21 15:41:57 2015 -0400
summary:
Issue 23898: Fix inspect.classify_class_attrs() to work with __eq__
files:
Lib/inspect.py | 6 +++---
Lib/test/test_inspect.py | 15 +++++++++++++++
Misc/NEWS | 3 +++
3 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -380,7 +380,7 @@
# 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:
@@ -388,7 +388,7 @@
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
@@ -402,7 +402,7 @@
# 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
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -782,6 +782,21 @@
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'
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -260,6 +260,9 @@
- asyncio: async() function is deprecated in favour of ensure_future().
+- Issue 23898: Fix inspect.classify_class_attrs() to support attributes
+ with overloaded __eq__ and __bool__. Patch by Mike Bayer.
+
Tests
-----
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list