Issue #8774: tabnanny uses the encoding cookie (#coding:...) to use the correct
encoding
diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py
index 2c6fb0c..7053fd9 100755
--- a/Lib/tabnanny.py
+++ b/Lib/tabnanny.py
@@ -93,8 +93,11 @@
                 check(fullname)
         return
 
+    with open(file, 'rb') as f:
+        encoding, lines = tokenize.detect_encoding(f.readline)
+
     try:
-        f = open(file)
+        f = open(file, encoding=encoding)
     except IOError as msg:
         errprint("%r: I/O Error: %s" % (file, msg))
         return