Re: Fw: lib2to3 and matching of fixers
Benjamin Peterson <benjamin <at> ...> writes:
> You have to account for the newline.
Thanks for the response, but it's not clear how or why. As to the "why": the
portion of the tree I get by looking at
which is the bit I expect to match. It does not contain the newline (that's
present as the last child the enclosing grandparent node (simple_stmt) obtained
by looking at tree.children:
The pattern I used appears consistent with the subset of the pattern used in
the is_instance fixer to match a tuple in the isinstance call, other than
whitespace in the pattern string itself:
trailer< '(' arglist< any ',' atom< '('
args=testlist_gexp< any+ >
')' > > ')' >
in the is_instance fixer, as against my fixer's
atom< '(' args=testlist_gexp< any+ > ')' >
So I can't see why the newline needs to be accounted for, nor how to do it.
Arranging the whitespace in my pattern to exactly match that segment in the
is_instance fixer's pattern made no difference, as I would have expected.
So, how do I account for the newline, and why do I need to when it's two levels
up in the tree?
Thanks for your patience with lib2to3 newbie.