Problem with literal arguments in the PATTERN string for a python 2to3 fixer

I'm writing a fixer for the 2to3 tool in python.

In my pattern string, I have a section where I'd like to match an empty string as an argument, or an empty unicode string. The relevant chunk of my pattern looks like:

(args='""' | args='u""')

My issue is the second option never matches. Even if it's alone, it won't match. However, if I simply say args=any and then output args, I can catch cases where args is exactly equal to the second option.

Is there some weird unicode handling thing going on? Why won't the second literal option ever match?


Because 2to3 pattern matching is designed to match tokens not literals, there is no way to do this directly.

Instead you could match (args=STRING) and then determine the value of the string argument inside the transformation function and handle it appropriately.

Need Your Help

Cleanly interrupt zeromq polling thread

java multithreading zeromq jeromq

I have a multithreaded application written in Java using jeromq 0.3.2. I'm working on putting it into the Tanuki service wrapper so that it runs as a windows service, and I'm having some trouble w...

Visual Studio 2010 - Can't add a data source through menu .net visual-studio-2010 datasource

I am developing an ASP.NET 4.0 website through visual studio 2010 and I am new to ASP.NET however I have had experience with VB.NET.