Thread: [Pyobjc-dev] [ pyobjc-Bugs-678818 ] Missing NSCFNumber to int conversions
Brought to you by:
ronaldoussoren
From: SourceForge.net <no...@so...> - 2003-02-01 22:10:58
|
Bugs item #678818, was opened at 2003-02-01 14:16 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=114534&aid=678818&group_id=14534 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: David Eppstein (eppstein) Assigned to: Nobody/Anonymous (nobody) Summary: Missing NSCFNumber to int conversions Initial Comment: The attached code shows two problems and one non-problem with NSCFNumber (a data type that arises when objc passes an integer value to a python routine -- in the code, python ints passed to undoManager get transmogrified into this type when an undo or redo is requested). 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") 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). Given these bobbles, I would have expected to also have problems with arithmetic expressions involving NSCFNumber, but that is a non-problem -- the arithmetic in the attached code behaves correctly. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=114534&aid=678818&group_id=14534 |
From: <bb...@ma...> - 2003-02-01 23:15:22
|
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? [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 "fixed" it and your test prog now spews: [bumbox:~/bbum-developer/sourceforge/pyobjc] bbum% python foo.py Increment by 3 to 3 Null decrement to 3 Null increment to 3 Decrement by 3 to 0 Is this correct? Change committed (along with a unit test). There is still a bug in NSNumber handling, though: [bumbox:~/bbum-developer/sourceforge/pyobjc] bbum% python Lib/Foundation/test/test_nsnumber.py -v testAsBool (__main__.TestNSNumber) ... FAIL testNSNumber (__main__.TestNSNumber) ... ok testStr (__main__.TestNSNumber) ... ok ====================================================================== FAIL: testAsBool (__main__.TestNSNumber) ---------------------------------------------------------------------- Traceback (most recent call last): File "Lib/Foundation/test/test_nsnumber.py", line 34, in testAsBool raise AssertionError, "%s is not true"%(a.description()) AssertionError: -0.01 is not true ---------------------------------------------------------------------- Ran 3 tests in 0.035s FAILED (failures=1) b.bum |
From: Just v. R. <ju...@le...> - 2003-02-01 23:25:11
|
bb...@ma... wrote: > On Saturday, Feb 1, 2003, at 17:16 US/Eastern, SourceForge.net wrote: Bill, not to be a pain in the neck, but it's really best to add comments to the bug report itself and not post directly to the list... Just |
From: <bb...@ma...> - 2003-02-01 23:28:53
|
On Saturday, Feb 1, 2003, at 18:24 US/Eastern, Just van Rossum wrote: > bb...@ma... wrote: > >> On Saturday, Feb 1, 2003, at 17:16 US/Eastern, SourceForge.net wrote: > > Bill, not to be a pain in the neck, but it's really best to add > comments > to the bug report itself and not post directly to the list... Yes -- I'm actually going to update the bug, but I wanted to open some of the discussion here because it involves adding a feature back to the bridge that was clearly removed at some point for some reason... b.bum |
From: David E. <epp...@ic...> - 2003-02-01 23:38:58
|
On 2/1/03 6:15 PM -0500 bb...@ma... wrote: > I "fixed" it and your test prog now spews: > > [bumbox:~/bbum-developer/sourceforge/pyobjc] bbum% python foo.py > Increment by 3 to 3 > Null decrement to 3 > Null increment to 3 > Decrement by 3 to 0 > > Is this correct? Yes. Was there a recent change that would have caused the "if x:" to work on your system and not on mine? My most recent cvs update was Jan. 23. Also, I'm not sufficiently familiar w/the sf bugtracker -- is there an address to include in email so that comments like this can get auto-attached to the bug? Or do all comments have to be done through the web page? -- David Eppstein UC Irvine Dept. of Information & Computer Science epp...@ic... http://www.ics.uci.edu/~eppstein/ |
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 |
From: <bb...@ma...> - 2003-02-02 17:37:43
|
On Sunday, Feb 2, 2003, at 12:21 US/Eastern, Ronald Oussoren wrote: > 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. Should probably undo that change that I made, then... :-) b.bum |