]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40209: Use tokenize.open in test_unparse (GH-19399)
authorHakan Çelik <hakancelik96@outlook.com>
Thu, 16 Apr 2020 10:11:55 +0000 (13:11 +0300)
committerGitHub <noreply@github.com>
Thu, 16 Apr 2020 10:11:55 +0000 (11:11 +0100)
Lib/test/test_unparse.py

index 23292640086b9370b8eccbf8272fde6de95a4ce1..d4089a3fc1cdf8f27d17dbbec7619509eba637a5 100644 (file)
@@ -11,11 +11,8 @@ import ast
 def read_pyfile(filename):
     """Read and return the contents of a Python source file (as a
     string), taking into account the file encoding."""
-    with open(filename, "rb") as pyfile:
-        encoding = tokenize.detect_encoding(pyfile.readline)[0]
-    with open(filename, "r", encoding=encoding) as pyfile:
-        source = pyfile.read()
-    return source
+    with tokenize.open(filename) as stream:
+        return stream.read()
 
 
 for_else = """\