Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93296

Re: How to debug TypeError: required field "lineno" missing from expr?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: How to debug TypeError: required field "lineno" missing from expr?
Date 2015-06-29 16:59 -0400
References <mmq666$1e7$1@ger.gmane.org> <201506290708.t5T78rhr024655@fido.openend.se> <mmr9g5$66h$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.172.1435611574.3674.python-list@python.org> (permalink)

Show all headers | View raw


On 6/29/2015 7:17 AM, Terry Reedy wrote:
> On 6/29/2015 3:08 AM, Laura Creighton wrote:
>> In a message of Mon, 29 Jun 2015 02:14:43 +0100, Mark Lawrence writes:
>>> Purely as an exercise I've been converting Grant Jenks' pypatt[1] from
>>> 2.7 to 3.4.  I've managed to sort out most of the required changes by
>>> checking on what I can see with an AST pretty printer[2].  So it's
>>> rather frustrating to have the compile stage throw the error given in
>>> the subject line.
>>
>> Are you trying to use ast.copy_location recursively somewhere?
>> http://bugs.python.org/issue3530   Maybe you have found something else
>> that doesn't work recursively?

The issue is that copy_location is not recursive and does not fix 
children of the node being fixed, whereas the example method, copied 
from the NodeTransformer doc, creates 3 new nodes, not just 1, that need 
fixing.  I reopened the issue as a doc issue to fix the example and 
recommend the use of recursive fix_missing_locations() instead of the 
non-recursive copy_location.

The only other location-related function in ast is increment_lineno, 
which also works on multiple nodes.  I would not be surprised is Mark's 
issue results from Mark or someone else copying the bad doc example.

> I do not understand the closing of this issue given that a) the failing
> part of the code is copied from the doc (3.4 has the same in the
> docstring) and b) that there is no recursion for a single node ast,
> which the example should be.

The original ast is actually an Expression with a Name.  But the issue 
is that the Name is replaced with a Subscript with Name and Str children 
and all three need locations added.

> The error message comes from
> F:\Python\dev\34\Python\Python-ast.c: 3752:
> PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from
> stmt");

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How to debug TypeError: required field "lineno" missing from expr? Terry Reedy <tjreedy@udel.edu> - 2015-06-29 16:59 -0400

csiph-web