作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我运行 2to3 -f all -f idioms -f buffer -f set_literal -f ws_comma foo.py
输出:
RefactoringTool: No changes to foo.py
RefactoringTool: Files that need to be modified:
RefactoringTool: foo.py
foo.py
的内容:
print("Hi")
我如何解释这个输出?
最佳答案
修改由the unicode
fixer触发.此修复程序将解释每个字符串文字的内容,并尝试重新转义无效的 Unicode 序列,并删除 u/U 字符串前缀:
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 仍然将其解释为正在更改的 token 树,因此它显示“需要修改的文件”。但是,实际的源代码是一样的,所以有“No changes to foo.py”。
如果第 3 步返回 None 而不是,它会真正说“没有文件需要修改”。
受影响的文件只会用原始输入重写。所以这个 bug 是无害的。
关于python - 2to3 说 "No changes needed",然后是 "files that need to be modified",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40240229/
我是一名优秀的程序员,十分优秀!