Skip to content

Commit 6a5bf15

Browse files
bpo-40209: Use tokenize.open in test_unparse (GH-19399)
1 parent 01508dc commit 6a5bf15

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

Lib/test/test_unparse.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
def read_pyfile(filename):
1212
"""Read and return the contents of a Python source file (as a
1313
string), taking into account the file encoding."""
14-
with open(filename, "rb") as pyfile:
15-
encoding = tokenize.detect_encoding(pyfile.readline)[0]
16-
with open(filename, "r", encoding=encoding) as pyfile:
17-
source = pyfile.read()
18-
return source
14+
with tokenize.open(filename) as stream:
15+
return stream.read()
1916

2017

2118
for_else = """\

0 commit comments

Comments
 (0)