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: ast.fix_missing_locations() breaks if node doesn't have "_attributes" variable
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, aronacher, marcin.bachry
Priority: normal Keywords: patch

Created on 2008-10-07 14:37 by marcin.bachry, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
ast.diff marcin.bachry, 2008-10-07 14:37 simple fix
asdl_c.diff aronacher, 2008-10-07 17:42
Messages (4)
msg74453 - (view) Author: Marcin Bachry (marcin.bachry) Date: 2008-10-07 14:37
ast.fix_missing_locations() fails if any node is missing "_attributes"
instance variable - but it's the case of some fundamental nodes like
"alias" or "identifier".  When I run simple test:

  import ast
  with open(__file__) as fp:
      tree = ast.parse(

I get:

  $ python2.6 /tmp/ 
  Traceback (most recent call last):
    File "/tmp/", line 5, in <module>
    File "/usr/local/lib/python2.6/", line 133, in
      _fix(node, 1, 0)
    File "/usr/local/lib/python2.6/", line 132, in _fix
      _fix(child, lineno, col_offset)
    File "/usr/local/lib/python2.6/", line 132, in _fix
      _fix(child, lineno, col_offset)
    File "/usr/local/lib/python2.6/", line 121, in _fix
      if 'lineno' in node._attributes:
  AttributeError: 'alias' object has no attribute '_attributes'
msg74465 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2008-10-07 17:42
The root of the problem is that ast.AST doesn't have _fields or
_attributes.  I think the better solution is to add these attributes to
the root class which makes it easier to work with these objects.

I attached a diff for which fixes that problem by adding
attributes to the AST class.

Run `python Parser/ -h Python Parser/Python.asdl` to regenerate
the Python-ast.c file.

Can someone review the diff?
msg74470 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-10-07 19:43
empty_tuple should be DECREF'ed at the end of the function.
Otherwise the patch is fine.
msg74968 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2008-10-19 08:30
Fixed in changeset 66973 for trunk.
Date User Action Args
2022-04-11 14:56:40adminsetgithub: 48317
2008-10-19 08:31:09aronachersetstatus: open -> closed
resolution: fixed
2008-10-19 08:30:40aronachersetmessages: + msg74968
2008-10-07 19:43:36amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg74470
2008-10-07 17:42:14aronachersetfiles: + asdl_c.diff
nosy: + aronacher
messages: + msg74465
2008-10-07 14:37:55marcin.bachrycreate