Skip to content
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

Future imports above encoding? #97

Closed
guettli opened this issue Sep 8, 2014 · 2 comments
Closed

Future imports above encoding? #97

guettli opened this issue Sep 8, 2014 · 2 comments

Comments

@guettli
Copy link

guettli commented Sep 8, 2014

Is this you inted? The imports are above the "# -- coding: utf-8 --" line.

AFAIK the coding should be at the top of the file.

+from __future__ import print_function
+from __future__ import division
+from __future__ import absolute_import
+from __future__ import unicode_literals
# -*- coding: utf-8 -*-

I think it is a bug.

What happens if there is "#!/usr/bin/python" at the top?

@edschofield
Copy link
Contributor

@guettli : Thanks for the report! This is now fixed in v0.14.2.

@bertsky
Copy link

bertsky commented Dec 12, 2019

I believe this needs to be re-opened. It only works if the encoding specifier is in the very first line (not if it's in the second), and only if it uses the -*- convention. But PEP 263 specifies the following regex (for the first or second line):

^[ \t\f]*#.*?coding[:=][ \t]*([-_.a-zA-Z0-9]+)

This licenses usage like the following (as can be seen in pyleptonica):

# coding: utf-8

But this gives (with future==0.18.2):

from __future__ import absolute_import

# coding: utf-8

...which does not work anymore, and yields a follow-up error in Python 2 (SyntaxError: Non-ASCII character ...)

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

3 participants