Skip to content

mypy gets confused by double coding cookie #1281

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
gvanrossum opened this issue Mar 9, 2016 · 4 comments
Closed

mypy gets confused by double coding cookie #1281

gvanrossum opened this issue Mar 9, 2016 · 4 comments
Labels
bug mypy got something wrong

Comments

@gvanrossum
Copy link
Member

When a file has two different coding cookies (one in line 1, one in line 2) mypy gets confused and uses the cookie from the second line. It should use the first.

Low priority; I found this by accident and the new parser will presumably make this go away.

@gvanrossum gvanrossum added the bug mypy got something wrong label Mar 9, 2016
@andersschuller
Copy link
Contributor

I remember reading through the PEP and the docs about this when I was considering picking up #522. I was slightly surprised that neither of them seem to document the expected behaviour when both the first and second lines contain a valid encoding comment. However it's entirely possible that I missed something, and in any case it's probably best to match the behaviour of CPython as you suggest.

@gvanrossum
Copy link
Member Author

FWIW I clarified this in the PEP.

ddfisher added a commit that referenced this issue Mar 17, 2016
When two coding cookies are present, use the first. Fixes #1281.
@serhiy-storchaka
Copy link
Member

The regular expression that matches the current behavior of CPython is br'(\xef\xbb\xbf)?([ \t\f]*(?:#.*)?(?:\r\n?|\n))??[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)'.

You should check the BOM, the first line can be blank, and \s in current regexp matches too wide range of whitespace characters (in particular '\n' and '\r').

@gvanrossum
Copy link
Member Author

gvanrossum commented Mar 21, 2016 via email

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

No branches or pull requests

3 participants