Re: [Pyobjc-dev] [ pyobjc-Bugs-678818 ] Missing NSCFNumber to int conversions
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-02-02 17:23:00
|
On Sunday, Feb 2, 2003, at 00:15 Europe/Amsterdam, bb...@ma... wrote: > On Saturday, Feb 1, 2003, at 17:16 US/Eastern, SourceForge.net wrote: >> 1. if x: should only execute the if clause when x is >> nonzero. But if x is a zero NSCFNumber, the clause >> gets executed erroneously (third line of code's output >> is "Increment by ..." instead of "Null increment") > > I believe this is working correctly on my system? Probably because I checked in a fix for this just before the weekend :-) NSCFNumber evaluates to true if the value returned by 'boolValue' does (as do all other objects that have a boolValue method) > > [bumbox:~/bbum-developer/sourceforge/pyobjc] bbum% python foo.py > Increment by 3 to 3 > Null decrement to 3 > Null increment to 3 > Decrement by <NSCFNumber objective-c instance 0x470330> to 0 > >> 2. str(x) should produce a decimal representation of x, >> but if x is an NSCFNumber, it instead produces a string >> like '<NSCFNumber objective-c instance 0x832ed0>' >> (third and fourth lines of code's output). > > This is definitely broken. Both str() and repr() do not do what one > might expect. > > Why doesn't str() invoke -description? ...or repr()? __repr__ > mapping to -description was commented out of _convenience.py. I have no idea why this was removed. ... Oh, I do know: If you invoke -description from __str__ and __repr__ you may cause a coredump if you do something like this in an interactive interpreter: >>> NSSomeClass.alloc() <NSSomeClass instance at 0xabcdabcd> >>> _.init() <NSSomeClass instance at 0xabcdabcd> For some values of 'NSSomeClass' the interpreter will crash when trying to print the repr of the return value of alloc. The interpreter seems to call __repr__, so we should be safe if we only map __str__ to description. Ronald |