recarray.__setattr__ bug?

Travis Oliphant oliphant.travis at ieee.org
Sun Oct 29 01:40:32 CST 2006


Michael McNeil Forbes wrote:
> In article <4543A153.4030505 at ieee.org>,
>  Travis Oliphant <oliphant.travis at ieee.org> wrote:
>   
>> Hmm.... I know that the code was changed at some point a few months ago 
>> specifically to this behavior because of some concerns Perry, Chris 
>> (people at STScI) had.   Originally, field names came first, but we 
>> changed it so they could set known attributes of a record array even if 
>> they were also field names.
>>
>> This may be an unintentional side-effect.    So, let's not just change 
>> things again and create problems for them.
>>     
>
> Were any test cases generated for this?  Changing the code did not break 
> anything: if this is important, a test should probably be added.
>   
You are right.  In fact there are lots of tests that need to be added.   
Stefan as been doing a great job of regression testing. 

I've committed some fixes to this particular issue that allows setattr 
to be used to set field names.  Now

1) The standard setattr is tried first

2) If it fails, then  the field-dictionary is checked to see if there is 
a field with that name.
      a)  If not, then the error created by 1 is raised
      b)  if the name is a field, then an attempt is made to set the 
field with that name

3) If the standard setattr succeeds then either i) a built-in attribute 
was correctly set or ii) a new attribute was created and attached to the 
dictionary.
      a)  If the attribute is not in the fields, then return
      b)  Otherwise, see if this name was in the .__dict__ before the 
call (if it's not
            then we just added it so delete it). 
            i) If the deletion succeeds then set set the field
            ii If the deletion fails, then return the result of standard 
setattr setting.


I've added a test for some of these behaviors.


-Travis



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list