Glenn wrote:
[...] but maybe bar at 4 and baz at 8 would be even better. In other words, I don't think pointing at the "." is useful? [...]
Hi,
here's a patch which results in what Glenn Linderman suggested:
--- python-orig/Python/ast.c 2010-10-19 03:22:07.000000000 +0200
+++ python-new/Python/ast.c 2010-12-27 20:33:55.000000000 +0100
@@ -1615,7 +1615,7 @@
if (!attr_id)
return NULL;
return Attribute(left_expr, attr_id, Load,
- LINENO(n), n->n_col_offset, c->c_arena);
+ LINENO(CHILD(n, 1)), CHILD(n,
1)->n_col_offset, c->c_arena);
}
else {
REQ(CHILD(n, 0), LSQB);
@@ -1742,8 +1742,6 @@
tmp = ast_for_trailer(c, ch, e);
if (!tmp)
return NULL;
- tmp->lineno = e->lineno;
- tmp->col_offset = e->col_offset;
e = tmp;
}
if (TYPE(CHILD(n, NCH(n) - 1)) == factor) {
This gives 0, 4, 8 as column offsets for foo.bar.baz and 0, 6, 14 for
foo. bar. baz, i.e. points to the beginning of the attribute
identifier.
What do you think?
Bye,
Sven
2010/12/27 Nick Coghlan
On Mon, Dec 27, 2010 at 9:34 AM, Benjamin Peterson
wrote: 2010/12/26 Sven Brauch
: In that discussion, there's been different opinions about which behaviour is better; main arguments were "consistency" for the current and "usefulness" for the suggested behaviour. It has been proposed to ask the question on this list, that's why I'm doing that now. :)
My argument against this change is that an attribute includes the expression from which the attribute is being taken. This is consistent with subscripts and calls, which both have the lineno and col_offset of their source expressions.
I'd like to see the impact on existing uses of this information (primarily SyntaxErrors) before forming a firm opinion, but my initial inclination is that retaining the column information for the subattribute names is a better option.
Cheers, Nick.
-- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia