Issue1059

classification
Title: Possible to construct long(None)
Type: behaviour Severity: normal
Components: Core Versions: 2.5alpha1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: nriley, pjenvey
Priority: Keywords:

Created on 2008-06-15.21:41:13 by nriley, last changed 2008-06-22.21:17:20 by pjenvey.

Messages
msg3289 (view) Author: Nicholas Riley (nriley) Date: 2008-06-15.21:41:11
Jython:

>>> x = long(None)
>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
java.lang.NullPointerException
	at org.python.core.PyLong.long_toString(PyLong.java:122)
	at org.python.core.PyLong.toString(PyLong.java:117)
	at org.python.core.PyObject.__repr__(PyObject.java:103)

CPython:

>>> long(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: long() argument must be a string or a number, not 'NoneType'

int(None) fails as expected.
msg3297 (view) Author: Nicholas Riley (nriley) Date: 2008-06-22.04:43:10
With r4699 long(None) now generates an AttributeError, which is quite a 
bit better.  Would it make sense to change long___new__ to trap this 
AttributeError and throw a TypeError, or is there a better way to do this?
msg3300 (view) Author: Philip Jenvey (pjenvey) Date: 2008-06-22.21:17:19
i made it translate the AttributeError to TypeError in r4713

technically this will swallow any user created AttributedErrors in a 
__long__ definition, but that's just kind of how Jython does things right 
now. We do a similar translation for e.g. __complex__
History
Date User Action Args
2008-06-22 21:17:20pjenveysetstatus: open -> closed
resolution: fixed
messages: + msg3300
2008-06-22 04:43:13nrileysetnosy: + pjenvey
messages: + msg3297
2008-06-15 21:41:13nrileycreate