non-string attributes in new SWIG objects cause exceptions in PyCrust

Dear list,

The CVS version of ITK (http://www.itk.org/) uses CableSwig, a mixture of GCC-XML, Cable and Swig. In anycase, in the latest version, it seems that wrapped objects have a non-string attribute name:

>>> print obj._geodesicActiveContour
<C itk::SmartPointer<(itk::GeodesicActiveContourLevelSetImageFilter<(itk::Image<(float,3)>,itk::Image<(float,3)>,float)>)> instance at _b01e8b00_p_itk__SmartPointerTitk__GeodesicActiveContourLevelSetImageFilterTitk__ImageTfloat_3_t_itk__ImageTfloat_3_t_float_t_t>
>>> [a for a in dir(obj._geodesicActiveContour) if type(a) != str]
[<class 'itkGeodesicActiveContourLevelSetImageFilter.itkGeodesicActiveContourLevelSetImageFilterF3F3_PointerPtr'>]
>>>

So, when one types in this case e.g. "obj._geodesicActiveContour." PyCrust raises an exception (it's supposed to show tooltips). It seems in "introspect.py", it's using .upper() whilst sorting the attribute list. This obivously does not work on the non-string attribute. This is in wxPython 2.4.2.4.

The attached patch fixes this by removing non-string attribute names in introspect.py. Maybe this is not an issue anymore in 2.5.x?

Thanks,
Charl

introspect.py-nonStringAttr.diff (572 Bytes)

···

--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/

Charl P. Botha wrote:

Dear list,

The CVS version of ITK (http://www.itk.org/) uses CableSwig, a mixture of GCC-XML, Cable and Swig. In anycase, in the latest version, it seems that wrapped objects have a non-string attribute name:

>>> print obj._geodesicActiveContour
<C itk::SmartPointer<(itk::GeodesicActiveContourLevelSetImageFilter<(itk::Image<(float,3)>,itk::Image<(float,3)>,float)>)> instance at _b01e8b00_p_itk__SmartPointerTitk__GeodesicActiveContourLevelSetImageFilterTitk__ImageTfloat_3_t_itk__ImageTfloat_3_t_float_t_t>

>>> [a for a in dir(obj._geodesicActiveContour) if type(a) != str]
[<class 'itkGeodesicActiveContourLevelSetImageFilter.itkGeodesicActiveContourLevelSetImageFilterF3F3_PointerPtr'>]

>>>

So, when one types in this case e.g. "obj._geodesicActiveContour." PyCrust raises an exception (it's supposed to show tooltips). It seems in "introspect.py", it's using .upper() whilst sorting the attribute list. This obivously does not work on the non-string attribute. This is in wxPython 2.4.2.4.

But arn't all object attributes in Python objects supposed to have string names? Maybe I missed something but it seems like this would break a lot more than introspection if they didn't.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Charl P. Botha wrote:

So, when one types in this case e.g. "obj._geodesicActiveContour." PyCrust raises an exception (it's supposed to show tooltips). It seems in "introspect.py", it's using .upper() whilst sorting the attribute list. This obivously does not work on the non-string attribute. This is in wxPython 2.4.2.4.

But arn't all object attributes in Python objects supposed to have string names? Maybe I missed something but it seems like this would break a lot more than introspection if they didn't.

That's what I thought too, but seeing it actually being done made me doubt that. This is also relatively easy to DIY(tm):

>>> blaat = 3
>>> locals()[blaat] = 4
>>> locals()
{3: 4, 'blaat': 3, '__builtins__': <module '__builtin__' (built-in)>, '__name__': '__main__', 'pywin': <module 'pywin' from 'pywin\__init__.pyc'>, '__doc__': None}
>>> meep = locals()
>>> [a for a in meep.keys() if type(a) != str]
[3]
>>>

In the light of this, maybe PyCrust should be robustified with my patch?

Thanks,
Charl

···

--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/

Charl P. Botha wrote:

Robin Dunn wrote:

Charl P. Botha wrote:

So, when one types in this case e.g. "obj._geodesicActiveContour." PyCrust raises an exception (it's supposed to show tooltips). It seems in "introspect.py", it's using .upper() whilst sorting the attribute list. This obivously does not work on the non-string attribute. This is in wxPython 2.4.2.4.

But arn't all object attributes in Python objects supposed to have string names? Maybe I missed something but it seems like this would break a lot more than introspection if they didn't.

That's what I thought too, but seeing it actually being done made me doubt that. This is also relatively easy to DIY(tm):

Via (abusive <wink>) dictionary manipulations yes, but can you create an item in a module or class via normal means that does not have a string name?

In the light of this, maybe PyCrust should be robustified with my patch?

Yes.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Charl P. Botha wrote:

> That's what I thought too, but seeing it actually being done made me
> doubt that. This is also relatively easy to DIY(tm):

Via (abusive <wink>) dictionary manipulations yes, but can you create an
item in a module or class via normal means that does not have a string name?

Oh, I'm sure I can't via the *normal* ways... :slight_smile:

>
> In the light of this, maybe PyCrust should be robustified with my patch?
>

Yes.

Great, thanks.

Best regards,
Charl

···

On Tue, 2004-04-27 at 01:19, Robin Dunn wrote:

--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/