MantisBT - ITK
View Issue Details
0001753ITKpublic2005-04-07 17:322010-11-04 22:48
John Hunter 
Luis Ibanez 
normalminoralways
closedfixed 
 
 
completed
0001753: dir returns non-string in python
In the python wrapper for ITK 2.0, calling dir on some objects returns a non string, eg

  >>> import InsightToolkit as itk
  >>> reader = itk.itkImageFileReaderF2_New()
  >>> dir(reader)
['AbortGenerateDataOff',
 'AbortGenerateDataOn',
...snip...
'this',
 'thisown',
 <class 'itkImageFileReader_2D.itkImageFileReaderF2_PointerPtr'>]

Accoring to the python docs, dir should return a list of strings. The behavior above breaks the completer module rlcompleter in the python standaard library, which relies on this list containing only strings.
No tags attached.
related to 0002095closed Gaetan Lehmann update SWIG in cableswig 
Issue History
2007-09-19 10:23Luis IbanezAssigned ToBrad King => Luis Ibanez
2007-09-19 10:23Luis IbanezNote Added: 0009117
2007-09-21 15:57Luis IbanezRelationship addedrelated to 0002095
2010-11-04 22:48Cory W QuammenSprint Status => completed
2010-11-04 22:48Cory W QuammenNote Added: 0022878
2010-11-04 22:48Cory W QuammenStatusassigned => closed
2010-11-04 22:48Cory W QuammenResolutionopen => fixed

Notes
(0002783)
Lydia Ng   
2005-08-05 15:26   
Triaged 8/5/05 tcon. Assigned to Brad.
(0002795)
Brad King   
2005-08-05 16:40   
ITK's wrapping process uses SWIG. It looks like this bug is inherited from that project. The following message from the SWIG mailing list explains it:

http://mailman.cs.uchicago.edu/pipermail/swig/2004-October/010716.html [^]

Josh Cherry jcherry@ncbi.nlm.nih.gov
Mon, 18 Oct 2004 15:16:37 -0400 (EDT)

    * Previous message: [Swig] SWIG sets non-string key in __dict__?
    * Next message: [Swig] Help needed please
    * Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

On Mon, 18 Oct 2004, Skip Montanaro wrote:

>
> I've noticed that SWIG seems to set values in a Python wrapper object's
> __dict__ using non-string keys. If obj is a SWIG-generated instance,
> something like
>
> print [k for k in dir(obj) if k.startswith("set_")]
>
> fails because one of the k's isn't a string or unicode object. Sure enough,
> looking at a simple dir() of a SWIG-generated object shows things like:
>
> ['__class__', '__del__', '__delattr__', '__dict__', '__doc__',
> '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__',
> '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
> '__str__', '__swig_getmethods__', '__swig_setmethods__', '__weakref__',
> 'context', 'instance', 'signal_timer', 'this', 'thisown',
> <class 'tradelink.glibEventLoop.v4_1.glibEventLoop.EventLoopPtr'>]
>
> (Note the last item in the list.)
>
> We're using SWIG 1.3.21, just one micro release older than the latest, so I
> suspect we're not "too old". Is this an ugly hack or a SWIG bug?

I pointed this out a while ago; see
http://mailman.cs.uchicago.edu/pipermail/swig/2004-January/008907.html. [^] I
don't know whether it's been fixed in 1.3.22, but using the -modern switch
should solve the problem.

Josh

--
Joshua L. Cherry, Ph.D.
NCBI/NLM/NIH (Contractor)
jcherry@ncbi.nlm.nih.gov

(0009117)
Luis Ibanez   
2007-09-19 10:23   
Luis will verify the current version of SWIG.
(0022878)
Cory W Quammen   
2010-11-04 22:48   
Assumed fixed. If not, will reopen.