[Python-checkins] cpython (merge 3.2 -> default): Merge 3.2

michael.foord python-checkins at python.org
Sun Dec 18 23:09:33 CET 2011


http://hg.python.org/cpython/rev/766136049b44
changeset:   74063:766136049b44
parent:      74061:03701ac95d25
parent:      74062:56731ccf2e86
user:        Michael Foord <michael at voidspace.org.uk>
date:        Sun Dec 18 22:09:27 2011 +0000
summary:
  Merge 3.2

files:
  Lib/inspect.py           |  10 ++++++----
  Lib/test/test_inspect.py |   5 +++++
  Misc/NEWS                |   3 +++
  3 files changed, 14 insertions(+), 4 deletions(-)


diff --git a/Lib/inspect.py b/Lib/inspect.py
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1109,7 +1109,7 @@
 
 def _check_class(klass, attr):
     for entry in _static_getmro(klass):
-        if not _shadowed_dict(type(entry)):
+        if _shadowed_dict(type(entry)) is _sentinel:
             try:
                 return entry.__dict__[attr]
             except KeyError:
@@ -1134,8 +1134,8 @@
             if not (type(class_dict) is types.GetSetDescriptorType and
                     class_dict.__name__ == "__dict__" and
                     class_dict.__objclass__ is entry):
-                return True
-    return False
+                return class_dict
+    return _sentinel
 
 def getattr_static(obj, attr, default=_sentinel):
     """Retrieve attributes without triggering dynamic lookup via the
@@ -1151,7 +1151,9 @@
     instance_result = _sentinel
     if not _is_type(obj):
         klass = type(obj)
-        if not _shadowed_dict(klass):
+        dict_attr = _shadowed_dict(klass)
+        if (dict_attr is _sentinel or
+            type(dict_attr) is types.MemberDescriptorType):
             instance_result = _check_instance(obj, attr)
     else:
         klass = obj
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
@@ -1004,6 +1004,11 @@
         self.assertEqual(inspect.getattr_static(instance, "spam"), 42)
         self.assertFalse(Thing.executed)
 
+    def test_module(self):
+        sentinel = object()
+        self.assertIsNot(inspect.getattr_static(sys, "version", sentinel),
+                         sentinel)
+
 class TestGetGeneratorState(unittest.TestCase):
 
     def setUp(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -419,6 +419,9 @@
 Library
 -------
 
+- Issue #11813: Fix inspect.getattr_static for modules. Patch by Andreas 
+  Stührk.
+
 - Issue #7502: Fix equality comparison for DocTestCase instances.  Patch by
   Cédric Krier.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list