2016-10-25 22 views
4

我跑,然後是 「需要進行修改的文件」 2to3 -f all -f idioms -f buffer -f set_literal -f ws_comma foo.py2to3的說: 「沒有變化需要」

輸出:的foo.py

RefactoringTool: No changes to foo.py 
RefactoringTool: Files that need to be modified: 
RefactoringTool: foo.py 

內容:

print("Hi") 

我如何解釋這個輸出?

回答

3

該修改由the unicode fixer觸發。該固定器將解釋每一個字符串文字的內容,並試圖再次逃跑無效的Unicode序列,並卸下U/U字符串前綴:(?BUG)

def transform(self, node, results): 
    ... 
    elif node.type == token.STRING: 
     # 1. Replace the invalid \u sequences. 
     val = node.value 
     if not self.unicode_literals and val[0] in '\'"' and '\\' in val: 
      val = r'\\'.join([ 
       v.replace('\\u', r'\\u').replace('\\U', r'\\U') 
       for v in val.split(r'\\') 
      ]) 

     # 2. Strip the leading `u` in u"...." 
     if val[0] in 'uU': 
      val = val[1:] 

     # 3. If the whole string is the same, return the original node. 
     if val == node.value: 
      return node # <-------------- 

     # 4. Otherwise, create a new node. 
     new = node.clone() 
     new.value = val 
     return new 

對於一些未知的原因,即使原始節點在步驟3中返回,lib2to3仍然解釋爲令牌樹被更改,所以它說「需要修改的文件」。但是,實際的源代碼是相同的,所以有「沒有更改foo.py」。

如果第3步返回None,它會真正地說「沒有文件需要修改」。

受影響的文件將被重寫爲原始輸入。所以這個bug是無害的。

2

根據Steven D'Aprano,這是一個錯誤,文本在輸出的第二行應該被解釋爲:

文件,其中包括一些固定器關心,無論是否 被修改。

就你的情況而言,foo.py代碼與Python 3完全兼容,並且不需要作爲輸出狀態的第一行進行更改。

+0

作者:「修復者關心的東西」......這是什麼意思?我必須在意嗎? – JETM

+2

@JETM澄清,這意味着該文件被檢查,而不是需要改變 –

+2

而我認爲*我*吸吮在用戶界面。 ;) – JETM