Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent Exception for int() conversion #51959

Closed
florentx mannequin opened this issue Jan 15, 2010 · 5 comments
Closed

Inconsistent Exception for int() conversion #51959

florentx mannequin opened this issue Jan 15, 2010 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@florentx
Copy link
Mannequin

florentx mannequin commented Jan 15, 2010

BPO 7710
Nosy @mdickinson, @abalkin, @ezio-melotti, @florentx

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-07-21.14:57:57.587>
created_at = <Date 2010-01-15.19:35:21.192>
labels = ['interpreter-core', 'type-bug']
title = 'Inconsistent Exception for int() conversion'
updated_at = <Date 2012-07-21.14:57:57.585>
user = 'https://github.com/florentx'

bugs.python.org fields:

activity = <Date 2012-07-21.14:57:57.585>
actor = 'flox'
assignee = 'none'
closed = True
closed_date = <Date 2012-07-21.14:57:57.587>
closer = 'flox'
components = ['Interpreter Core']
creation = <Date 2010-01-15.19:35:21.192>
creator = 'flox'
dependencies = []
files = []
hgrepos = []
issue_num = 7710
keywords = []
message_count = 5.0
messages = ['97839', '97841', '97842', '146594', '166037']
nosy_count = 5.0
nosy_names = ['exarkun', 'mark.dickinson', 'belopolsky', 'ezio.melotti', 'flox']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue7710'
versions = ['Python 2.7']

@florentx
Copy link
Mannequin Author

florentx mannequin commented Jan 15, 2010

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').

@florentx florentx mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jan 15, 2010
@florentx
Copy link
Mannequin Author

florentx mannequin commented Jan 15, 2010

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

@exarkun
Copy link
Mannequin

exarkun mannequin commented Jan 15, 2010

Loosely related to bpo-4221.

@florentx florentx mannequin added the type-bug An unexpected behavior, bug, or error label Aug 12, 2010
@florentx
Copy link
Mannequin Author

florentx mannequin commented Oct 29, 2011

On 3.2 it is fixed (I didn't find the related changeset).

Not backported to 2.7.

@florentx
Copy link
Mannequin Author

florentx mannequin commented Jul 21, 2012

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'

@florentx florentx mannequin closed this as completed Jul 21, 2012
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants