Skip to content

Stugben: Handling files with file encoding comment #3726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ashwch opened this issue Jul 17, 2017 · 1 comment
Closed

Stugben: Handling files with file encoding comment #3726

ashwch opened this issue Jul 17, 2017 · 1 comment

Comments

@ashwch
Copy link
Contributor

ashwch commented Jul 17, 2017

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.

@gvanrossum
Copy link
Member

IMO stubgen should be made to understand encoding declarations the same way mypy does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants