Index: Tools/scripts/reindent.py =================================================================== --- Tools/scripts/reindent.py (revision 85501) +++ Tools/scripts/reindent.py (working copy) @@ -35,7 +35,7 @@ The backup file is a copy of the one that is being reindented. The ".bak" file is generated with shutil.copy(), but some corner cases regarding -user/group and permissions could leave the backup file more readable that +user/group and permissions could leave the backup file more readable than you'd prefer. You can always use the --nobackup option to prevent this. """ @@ -127,7 +127,7 @@ shutil.copyfile(file, bak) if verbose: print("backed up", file, "to", bak) - with open(file, "w") as f: + with open(file, 'w', newline=r.newlines) as f: r.write(f) if verbose: print("wrote new", file) @@ -175,6 +175,10 @@ # indeed, they're our headache! self.stats = [] + # Save the newlines found in the file so they can be used to + # create output without mutating the newlines. + self.newlines = f.newlines + def run(self): tokens = tokenize.generate_tokens(self.getline) for _token in tokens: