[Python-porting] Some questions about build_py_2to3

Benjamin Peterson musiccomposition at gmail.com
Tue Dec 9 02:47:24 CET 2008


On Mon, Dec 8, 2008 at 5:18 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> Thomas Heller wrote:
>> I have some beginners questions about distutils build_py_2to3 command:
>>
>> - Can it convert doctests?  How?
>
> It only converts what lib2to3 converts - so the question really is
> whether lib2to3 can convert doctests. AFAICT, no doctest fixer has been
> written yet (although it should be possible to write on - probably on
> an opt-in basis).

Yes, it can!

$ cat example.py
def add(a, b):
    """
    >>> print add(2, 4)
    6
    """
    return a + b

$ 2to3 -d example.py
--- example.py (original)
+++ example.py (refactored)
@@ -1,6 +1,6 @@
 def add(a, b):
     """
-    >>> print add(2, 4)
+    >>> print(add(2, 4))
     6
     """
     return a + b
RefactoringTool: Files that need to be modified:
RefactoringTool: example.py


> Whether or not warnings should be issued is a different question.
> Not sure whether 2to3 already issues warnings in some cases, and,
> if it does, whether build_py_2to3 displays them.

Warnings from 2to3 fixers get dumped into RefactoringTool's log_message.



-- 
Cheers,
Benjamin Peterson
"There's nothing quite as beautiful as an oboe... except a chicken
stuck in a vacuum cleaner."


More information about the Python-porting mailing list