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

Syntax Error on leading 0 in integer tokens #77485

Closed
jackb mannequin opened this issue Apr 18, 2018 · 3 comments
Closed

Syntax Error on leading 0 in integer tokens #77485

jackb mannequin opened this issue Apr 18, 2018 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@jackb
Copy link
Mannequin

jackb mannequin commented Apr 18, 2018

BPO 33304
Nosy @stevendaprano

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 2018-04-18.01:25:39.376>
created_at = <Date 2018-04-18.01:11:07.224>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'Syntax Error on leading 0 in integer tokens'
updated_at = <Date 2018-04-18.01:48:19.620>
user = 'https://bugs.python.org/jackb'

bugs.python.org fields:

activity = <Date 2018-04-18.01:48:19.620>
actor = 'steven.daprano'
assignee = 'none'
closed = True
closed_date = <Date 2018-04-18.01:25:39.376>
closer = 'steven.daprano'
components = ['Interpreter Core']
creation = <Date 2018-04-18.01:11:07.224>
creator = 'jackb'
dependencies = []
files = []
hgrepos = []
issue_num = 33304
keywords = []
message_count = 3.0
messages = ['315429', '315430', '315432']
nosy_count = 2.0
nosy_names = ['steven.daprano', 'jackb']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue33304'
versions = ['Python 3.4']

@jackb
Copy link
Mannequin Author

jackb mannequin commented Apr 18, 2018

Entering 007 gives a syntax error. Should return 7.
00 correctly returns 0.
007. correctly returns 7.0.

@jackb jackb mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Apr 18, 2018
@stevendaprano
Copy link
Member

This is not a bug, it is intentional.

In Python 2, numbers with a leading zero are interpreted as octal, leading to surprising results:

py> 015
13

In Python 3, we use 0o15 to get octal, and 015 becomes a syntax error.

@stevendaprano
Copy link
Member

I've opened an issue to improve the error message: bpo-33305

@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

1 participant