diff -r be3b41703822 Lib/tokenize.py --- a/Lib/tokenize.py Tue Mar 10 16:32:50 2015 +0100 +++ b/Lib/tokenize.py Tue Mar 10 10:09:58 2015 -0700 @@ -24,6 +24,7 @@ __credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, ' 'Skip Montanaro, Raymond Hettinger, Trent Nelson, ' 'Michael Foord') +import builtins from codecs import lookup, BOM_UTF8 import collections from io import TextIOWrapper @@ -428,8 +429,9 @@ return default, [first, second] - -_builtin_open = open +# Store this in the module to make it more reliably available at interpreter +# shutdown (issue 22599) +_builtin_open = builtins.open def open(filename): """Open a file in read only mode using the encoding detected by