2to3 says “No changes are required,” then “files that need to be changed,”

I ran 2to3 -f all -f idioms -f buffer -f set_literal -f ws_comma foo.py

Output:

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

Content foo.py :

 print("Hi") 

How to interpret this conclusion?

+5
source share
2 answers

This modification is triggered by the unicode lock . This latch will interpret the contents of all string literals and will try to avoid the invalid Unicode sequences again and remove the u / U string prefix:

 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 

For some unknown reason (error?), Even if the source node is returned in step 3, lib2to3 still interprets this as changing the token tree, so it says “Files to change”. However, the source code is the same, so there is “No change to foo.py”.

If step 3 returns None instead, it really says, "There are no files that need to be changed."

The infected files will simply be overwritten with the original input. So the error is harmless.

+3
source

According to Stephen D'Aprano , this is a mistake, and the second line of text in your view should be interpreted as:

Files that include what takes care of the latch, regardless of whether it changes.

In your case, the code foo.py perfectly compatible with Python 3, and no changes are needed, since the first status line is your output.

+2
source

Source: https://habr.com/ru/post/1258748/


All Articles