[Zope3-checkins] SVN: Zope3/branches/3.3/src/zope/app/apidoc/utilities. Fixed issue 664, http://www.zope.org/Collectors/Zope3-dev/664.

Jim Fulton jim at zope.com
Tue Jul 18 12:11:03 EDT 2006


Log message for revision 69174:
  Fixed issue 664, http://www.zope.org/Collectors/Zope3-dev/664.
  
  The introspector didn't properly handle attributes that showd up in
  dir() but that weren't gettable.
  

Changed:
  U   Zope3/branches/3.3/src/zope/app/apidoc/utilities.py
  U   Zope3/branches/3.3/src/zope/app/apidoc/utilities.txt

-=-
Modified: Zope3/branches/3.3/src/zope/app/apidoc/utilities.py
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/utilities.py	2006-07-18 15:37:49 UTC (rev 69173)
+++ Zope3/branches/3.3/src/zope/app/apidoc/utilities.py	2006-07-18 16:11:02 UTC (rev 69174)
@@ -227,8 +227,14 @@
     for attr in dir(obj):
         if attr.startswith('_'):
             continue
-        else:
-            attrs.append(attr)
+        
+        try:
+            getattr(obj, attr)
+        except AttributeError:
+            continue
+
+        attrs.append(attr)
+
     return attrs
 
 def getInterfaceForAttribute(name, interfaces=_marker, klass=_marker,

Modified: Zope3/branches/3.3/src/zope/app/apidoc/utilities.txt
===================================================================
--- Zope3/branches/3.3/src/zope/app/apidoc/utilities.txt	2006-07-18 15:37:49 UTC (rev 69173)
+++ Zope3/branches/3.3/src/zope/app/apidoc/utilities.txt	2006-07-18 16:11:02 UTC (rev 69174)
@@ -477,6 +477,10 @@
 
 First we need to create a class with some attributes, properties and methods:
 
+  >>> class Nonattr(object):
+  ...     def __get__(*a):
+  ...         raise AttributeError('nonattr')
+
   >>> class Sample(object):
   ...     attr = None
   ...     def __str__(self):
@@ -486,6 +490,8 @@
   ...     def _getAttr(self):
   ...         return self.attr
   ...     attr2 = property(_getAttr)
+  ...
+  ...     nonattr = Nonattr() # Should not show up in public attrs
 
 We can simply pass in the class and get the public attributes:
 
@@ -494,6 +500,9 @@
   >>> attrs
   ['attr', 'attr2', 'func']
 
+Note that we exclude attributes that would raise attribute errors,
+like our silly Nonattr.
+
 But an instance of that class will work as well.
 
   >>> attrs = utilities.getPublicAttributes(Sample())
@@ -752,4 +761,4 @@
 often safer (if available):
 
   >>> utilities.renderText('Hello!\n', module=apidoc)
-  u'<p>Hello!</p>\n'
\ No newline at end of file
+  u'<p>Hello!</p>\n'



More information about the Zope3-Checkins mailing list