[PEAK] peak binding.Component vs inspect

Phillip J. Eby pje at telecommunity.com
Sat Mar 12 14:45:18 EST 2005


At 12:37 PM 3/12/05 -0600, Doug Quale wrote:
>I am not able to get the inspect module to work with
>binding.Component.
>
>With Python 2.4.1 and peak from CVS on Feb 23, I get
>
> >>> from peak.api import binding
> >>> class Car(binding.Component):
>...     passengers = binding.Make(dict)
>...
> >>> aCar = Car()
> >>> import inspect
> >>> inspect.getmembers(aCar)
>Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/usr/lib/python2.4/inspect.py", line 171, in getmembers
>     value = getattr(object, key)
>   File "/usr/local/lib/python2.4/site-packages/protocols/classic.py", 
> line 147, in __get__
>     raise AttributeError(
>AttributeError: __conform__ registry does not pass to instances
> >>>
>
>Should I be trying this a different way?

Yes, as inspect.getmembers() is just broken.  It has the same problem with 
__slots__ that might not contain a value.  For example, try this:

 >>> class X(object): __slots__ = 'foo'
 >>> import inspect
 >>> inspect.getmembers(x())
Traceback (most recent call last):
   File "<pyshell#4>", line 1, in -toplevel-
     inspect.getmembers(X())
   File "C:\PYTHON23\lib\inspect.py", line 171, in getmembers
     value = getattr(object, key)
AttributeError: foo
 >>>


>Thanks for any help you can give me.

You might try writing a version of getmembers() that wraps the getattr() 
call in a try/except block, and perhaps submitting the patch to get back 
into Python.




More information about the PEAK mailing list