This seems like a noble pursuit. File a bug on with the results you posted here, and submit a PR via GitHub (

On Sat, Apr 11, 2020 at 9:09 AM Barry Scott <> wrote: does not open source files in "rb" which
prevents compile() from applying the encoding rules.

This first showed up for me on Windows with Python 3.8.

I'd like to provide patches for 3.8 (if any more releases)
and 3.9.

What is the process I should follow?
I have signed the Contributor Agreement.

Here is my test case and the results on Windows with 3.7.

import modulefinder

with open('', 'w') as f:
    f.write('import functools\n')

mf = modulefinder.ModuleFinder()
print('Test passed')

py -3.8-32
Traceback (most recent call last):
  File "", line 7, in <module>
  File "C:\Python38.win32\lib\", line 165, in run_script
    self.load_module('__main__', fp, pathname, stuff)
  File "C:\Python38.win32\lib\", line 360, in load_module
    self.scan_code(co, m)
  File "C:\Python38.win32\lib\", line 433, in scan_code
    self._safe_import_hook(name, m, fromlist, level=0)
  File "C:\Python38.win32\lib\", line 378, in _safe_import_hook
    self.import_hook(name, caller, level=level)
  File "C:\Python38.win32\lib\", line 177, in import_hook
    q, tail = self.find_head_package(parent, name)
  File "C:\Python38.win32\lib\", line 233, in find_head_package
    q = self.import_module(head, qname, parent)
  File "C:\Python38.win32\lib\", line 326, in import_module
    m = self.load_module(fqname, fp, pathname, stuff)
  File "C:\Python38.win32\lib\", line 343, in load_module
    co = compile('\n', pathname, 'exec')
  File "C:\Python38.win32\lib\encodings\", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 308: character maps to <undefined>

Python-Dev mailing list --
To unsubscribe send an email to
Message archived at
Code of Conduct:

--Guido van Rossum (
Pronouns: he/him (why is my pronoun here?)