Skip to content

Stugben: Handling files with file encoding comment #3726

Closed
@ashwch

Description

@ashwch

I was trying to generate stubs for sre_compile and it fails with:

$ python stubgen.py --py2 sre_compile
.../2.7/lib/python2.7/sre_compile.py:0: error: encoding declaration in Unicode string

This is probably happening because ast27_parse_impl converts source from bytes to string and tries to parse it without caring about source code encoding comment.

PEP 263 says:

If a Unicode string with a coding declaration is passed to compile() , a SyntaxError will be raised.

One quick fix would be to remove such comment from source before it is passed to mypy.parse.parse() in stubgen.py.

I am wondering if this is worth fixing? If yes, is the above the best way to do it.

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