You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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').
Activity
andersschuller commentedon Mar 15, 2016
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 commentedon Mar 17, 2016
FWIW I clarified this in the PEP.
Merge pull request #1296 from gvanrossum/coding
serhiy-storchaka commentedon Mar 21, 2016
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
\sin current regexp matches too wide range of whitespace characters (in particular'\n'and'\r').gvanrossum commentedon Mar 21, 2016