Skip to content

retype doesn't check source encodings before parsing #2

Description

@movermeyer

I was trying to retype a file, but the file had a comment that contained Unicode characters.

Example file (core.py):

#This is a comment with unicode characters: "Афон"
foo = "bar"

Example stub (types/core.pyi):

foo = ... # type: str
$>retype --traceback core.py
error: core.py: 'charmap' codec can't decode byte 0x90 in position 72: character maps to <undefined>
Traceback (most recent call last):
  File "retype.py", line 110, in retype_path
    retype_file(src, pyi_dir, targets, quiet=quiet, hg=hg)
  File "retype.py", line 131, in retype_file
    src_txt = src_file.read()
  File "Python36-32\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 72: character maps to <undefined>

I would have expected it to not crash on files with Unicode characters, especially since the characters are within comments.

Tested using:

  • Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)] on win32

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions