From 0860a0bd3f7859ca5786a9bb9b3c4b6c0e7a1f8d Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 31 Jan 2014 14:28:44 -0500 Subject: [PATCH] inspect.classify_class_attrs: Classify object.__new__ and __init__ correctly #18801 --- Lib/inspect.py | 2 +- Lib/test/test_inspect.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index e6c7b5b634e..8de9892afe2 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -412,7 +412,7 @@ def classify_class_attrs(cls): elif isinstance(dict_obj, property): kind = "property" obj = dict_obj - elif isfunction(obj) or ismethoddescriptor(obj): + elif isroutine(obj): kind = "method" else: kind = "data" diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index f06b5b4ff47..477f6016289 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -646,6 +646,10 @@ class TestClassesAndFunctions(unittest.TestCase): md = _BrokenMethodDescriptor() attrs = attrs_wo_objs(A) + + self.assertIn(('__new__', 'method', object), attrs, 'missing __new__') + self.assertIn(('__init__', 'method', object), attrs, 'missing __init__') + self.assertIn(('s', 'static method', A), attrs, 'missing static method') self.assertIn(('c', 'class method', A), attrs, 'missing class method') self.assertIn(('p', 'property', A), attrs, 'missing property')