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

The AST for dict and set displays has the lineno of the first value #69318

Closed
PCManticore mannequin opened this issue Sep 15, 2015 · 4 comments
Closed

The AST for dict and set displays has the lineno of the first value #69318

PCManticore mannequin opened this issue Sep 15, 2015 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@PCManticore
Copy link
Mannequin

PCManticore mannequin commented Sep 15, 2015

BPO 25131
Nosy @terryjreedy, @vstinner, @benjaminp, @PCManticore, @NeilGirdhar

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 2015-09-26.05:46:24.811>
created_at = <Date 2015-09-15.18:28:25.885>
labels = ['type-bug', 'library']
title = 'The AST for dict and set displays has the lineno of the first value'
updated_at = <Date 2015-09-26.05:46:24.809>
user = 'https://github.com/PCManticore'

bugs.python.org fields:

activity = <Date 2015-09-26.05:46:24.809>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2015-09-26.05:46:24.811>
closer = 'python-dev'
components = ['Library (Lib)']
creation = <Date 2015-09-15.18:28:25.885>
creator = 'Claudiu.Popa'
dependencies = []
files = []
hgrepos = []
issue_num = 25131
keywords = ['3.5regression']
message_count = 4.0
messages = ['250790', '250793', '251041', '251636']
nosy_count = 6.0
nosy_names = ['terry.reedy', 'vstinner', 'benjamin.peterson', 'Claudiu.Popa', 'python-dev', 'NeilGirdhar']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25131'
versions = ['Python 3.5', 'Python 3.6']

@PCManticore
Copy link
Mannequin Author

PCManticore mannequin commented Sep 15, 2015

Hi,

In Python 3.5, the lineno for dict and set display ASTs is the line number of the first value, not the line number of the display character, as it was until 3.5. Here's an example:

  from ast import parse
  module = parse('''{
           '1':'2',
  }
  ''')
  dict_display = module.body[0].value
  print(dict_display.lineno)

I don't seem to find anything related to this in the documentation, but I presume this is a side effect of the new parser changes. It would nice to have this fixed or at least documented.

@PCManticore PCManticore mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 15, 2015
@terryjreedy
Copy link
Member

A fix should include a new ast test, such as
self.assertEqual(parse("{\n1:2}").body[0].value.lineno, 1)
I verified that the equivalent assert passes on 3.4.3, fails on 3.5.0.

@python-dev
Copy link
Mannequin

python-dev mannequin commented Sep 26, 2015

New changeset 4f14afc959df by Benjamin Peterson in branch '3.5':
make opening brace of container literals and comprehensions correspond to the line number and col offset of the AST node (closes bpo-25131)
https://hg.python.org/cpython/rev/4f14afc959df

New changeset 9d895c09c08a by Benjamin Peterson in branch 'default':
merge 3.5 (bpo-25131)
https://hg.python.org/cpython/rev/9d895c09c08a

@python-dev python-dev mannequin closed this as completed Sep 26, 2015
@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
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants