[Python-checkins] r86579 - in python/branches/py3k/Lib: inspect.py test/test_inspect.py
michael.foord
python-checkins at python.org
Sat Nov 20 17:58:30 CET 2010
Author: michael.foord
Date: Sat Nov 20 17:58:30 2010
New Revision: 86579
Log:
Issue 9732: __class__ no longer checked on objects by getattr_static
Modified:
python/branches/py3k/Lib/inspect.py
python/branches/py3k/Lib/test/test_inspect.py
Modified: python/branches/py3k/Lib/inspect.py
==============================================================================
--- python/branches/py3k/Lib/inspect.py (original)
+++ python/branches/py3k/Lib/inspect.py Sat Nov 20 17:58:30 2010
@@ -1080,6 +1080,13 @@
pass
return _sentinel
+def _is_type(obj):
+ try:
+ _static_getmro(obj)
+ except TypeError:
+ return False
+ return True
+
def getattr_static(obj, attr, default=_sentinel):
"""Retrieve attributes without triggering dynamic lookup via the
@@ -1093,7 +1100,7 @@
documentation for details.
"""
instance_result = _sentinel
- if not isinstance(obj, type):
+ if not _is_type(obj):
instance_result = _check_instance(obj, attr)
klass = type(obj)
else:
Modified: python/branches/py3k/Lib/test/test_inspect.py
==============================================================================
--- python/branches/py3k/Lib/test/test_inspect.py (original)
+++ python/branches/py3k/Lib/test/test_inspect.py Sat Nov 20 17:58:30 2010
@@ -860,11 +860,15 @@
foo = 3
class Something(Base):
+ executed = False
@property
def __class__(self):
+ self.executed = True
return object
- self.assertEqual(inspect.getattr_static(Something(), 'foo'), 3)
+ instance = Something()
+ self.assertEqual(inspect.getattr_static(instance, 'foo'), 3)
+ self.assertFalse(instance.executed)
self.assertEqual(inspect.getattr_static(Something, 'foo'), 3)
def test_mro_as_property(self):
More information about the Python-checkins
mailing list