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.

Title: The AST for dict and set displays has the lineno of the first value
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu.Popa, NeilGirdhar, benjamin.peterson, python-dev, terry.reedy, vstinner
Priority: normal Keywords: 3.5regression

Created on 2015-09-15 18:28 by Claudiu.Popa, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg250790 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2015-09-15 18:28

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('''{
  dict_display = module.body[0].value

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.
msg250793 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-15 18:47
Using hg bisect, I found the revision a65f685ba8c0:
changeset:   95886:a65f685ba8c0
user:        Benjamin Peterson <>
date:        Tue May 05 20:16:41 2015 -0400
files:       Grammar/Grammar Include/Python-ast.h Include/dictobject.h Include/opcode.h Lib/importlib/ Lib/ Lib/test/ Lib/test/ Lib/test/ Lib/test/ Lib/test/ Lib/test/ Misc/ACKS Misc/NEWS Modules/parsermodule.c Objects/dictobject.c Parser/Python.asdl Python/Python-ast.c Python/ast.c Python/ceval.c Python/compile.c Python/graminit.c Python/importlib_external.h Python/opcode_targets.h Python/symtable.c Tools/parser/
PEP 448: additional unpacking generalizations (closes #2292)

Patch by Neil Girdhar.
msg251041 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2015-09-18 23:19
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.
msg251636 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-26 05:46
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 #25131)

New changeset 9d895c09c08a by Benjamin Peterson in branch 'default':
merge 3.5 (#25131)
Date User Action Args
2022-04-11 14:58:21adminsetgithub: 69318
2015-09-26 05:46:24python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg251636

resolution: fixed
stage: test needed -> resolved
2015-09-23 11:09:41berker.peksagsetkeywords: + 3.5regression
2015-09-18 23:19:22terry.reedysetnosy: + terry.reedy

messages: + msg251041
stage: test needed
2015-09-15 18:52:17vstinnersetnosy: + NeilGirdhar
2015-09-15 18:47:00vstinnersetnosy: + vstinner, benjamin.peterson
messages: + msg250793
2015-09-15 18:28:25Claudiu.Popacreate