homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Inconsistent Exception for int() conversion
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, exarkun, ezio.melotti, flox, mark.dickinson
Priority: normal Keywords:

Created on 2010年01月15日 19:35 by flox, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (5)
msg97839 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年01月15日 19:35
On Python 3:
>>> int('0円')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'decimal' codec can't encode character '\x00' in position 0: invalid decimal Unicode string
>>> int('01円')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '\x01'
>>> int('\x80')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: unexpected code byte
>>> int('\xc0')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf8' codec can't decode byte 0xc0 in position 0: unexpected end of data
On Python 2, it raises ValueError (except for '0円').
msg97841 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010年01月15日 20:26
The null byte gives UnicodeEncodeError for other conversions too.
Python 3:
 int('0円'), float('0円'), complex('0円')
Python 2:
 int(u'0円'), long(u'0円'), float(u'0円'), complex(u'0')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'decimal' codec can't encode character u'\x00' in position 1: invalid decimal Unicode string
msg97842 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010年01月15日 20:28
Loosely related to issue4221.
msg146594 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2011年10月29日 02:55
On 3.2 it is fixed (I didn't find the related changeset).
Not backported to 2.7.
msg166037 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2012年07月21日 14:57
The behavior seems acceptable in 2.7 too.
>>> int('0円')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: ''
>>> int('01円')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '\x01'
>>> int(u'0円')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'decimal' codec can't encode character u'\x00' in position 0: invalid decimal Unicode string
>>> int(u'01円')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '\x01'
History
Date User Action Args
2022年04月11日 14:56:56adminsetgithub: 51959
2012年07月21日 14:57:57floxsetstatus: open -> closed
resolution: fixed
messages: + msg166037

stage: test needed -> resolved
2011年10月29日 02:55:10floxsetmessages: + msg146594
versions: - Python 3.1, Python 3.2
2010年08月12日 18:10:40floxsetnosy: + belopolsky
stage: test needed
type: behavior

versions: + Python 3.1, Python 2.7
2010年08月12日 18:09:27floxlinkissue9578 superseder
2010年08月12日 17:55:06ezio.melottisetnosy: + ezio.melotti
2010年01月20日 12:44:32mark.dickinsonsetnosy: + mark.dickinson
2010年01月15日 20:28:10exarkunsetnosy: + exarkun
messages: + msg97842
2010年01月15日 20:26:22floxsetmessages: + msg97841
2010年01月15日 19:35:21floxcreate

AltStyle によって変換されたページ (->オリジナル) /