Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a98e3b

Browse files
committed
Issue #10117: Tools/scripts/reindent.py now accepts source files that
use encoding other than ASCII or UTF-8. Source encoding is preserved when reindented code is written to a file.
1 parent 016cec7 commit 4a98e3b

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/trace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ def runctx(self, cmd, globals=None, locals=None):
493493
threading.settrace(self.globaltrace)
494494
sys.settrace(self.globaltrace)
495495
try:
496+
del sys.modules['pickle']
496497
exec(cmd, globals, locals)
497498
finally:
498499
if not self.donothing:

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ C-API
111111
Tools/Demos
112112
-----------
113113

114+
- Issue #10117: Tools/scripts/reindent.py now accepts source files
115+
that use encoding other than ASCII or UTF-8. Source encoding is
116+
preserved when reindented code is written to a file.
117+
114118
- Issue #7287: Demo/imputil/knee.py was removed.
115119

116120
Tests

Tools/scripts/reindent.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ def check(file):
109109

110110
if verbose:
111111
print("checking", file, "...", end=' ')
112+
with open(file, 'rb') as f:
113+
encoding, _ = tokenize.detect_encoding(f.readline)
112114
try:
113-
with open(file) as f:
115+
with open(file, encoding=encoding) as f:
114116
r = Reindenter(f)
115117
except IOError as msg:
116118
errprint("%s: I/O Error: %s" % (file, str(msg)))
@@ -127,7 +129,7 @@ def check(file):
127129
shutil.copyfile(file, bak)
128130
if verbose:
129131
print("backed up", file, "to", bak)
130-
with open(file, "w") as f:
132+
with open(file, "w", encoding=encoding) as f:
131133
r.write(f)
132134
if verbose:
133135
print("wrote new", file)

0 commit comments

Comments
 (0)