[Python-porting] Fw: lib2to3 and matching of fixers

Benjamin Peterson benjamin at python.org
Wed Dec 14 18:35:25 CET 2011


2011/12/14 Vinay Sajip <vinay_sajip at yahoo.co.uk>:
>>> What are you using exactly? I would expect "atom< STRING+>" to
>
>>> work.
>>
>>Thanks, that worked. I tried "atom" and "STRING+" separately - sorry, I'm unfamiliar with the pattern-matching
>> language, but hopefully I'll get more familiar as I work with it!
>
>
> I'm now trying to match a tuple using the following pattern:
>
> PATTERN = "atom< '(' args=testlist_gexp< any+ > ')' >"
>
>
> This is a subset of the pattern used in the isinstance fixer that Armin Ronacher wrote. However, the pattern fails to match the source
>
> x = (int, long)
>
>
> The parse tree for this source looks like this:
>
> Node(file_input, [Node(simple_stmt, [Node(expr_stmt, [Leaf(1, 'x'), Leaf(22, '='), Node(atom, [Leaf(7, '('), Node(testlist_gexp, [Leaf(1, 'int'), Leaf(12, ','), Leaf(1, 'long')]), Leaf(8, ')')])]), Leaf(4, '\n')]), Leaf(0, '')])

You have to account for the newline.


-- 
Regards,
Benjamin


More information about the Python-porting mailing list