Skip to content

mypy gets confused by double coding cookie #1281

Closed

Description

@gvanrossum

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.

Activity

  1. added
    bug
    on Mar 9, 2016
  2. andersschuller commented on Mar 15, 2016

    @andersschuller
    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.

  3. gvanrossum commented on Mar 17, 2016

    @gvanrossum
    MemberAuthor

    FWIW I clarified this in the PEP.

  4. added a commit that references this issue on Mar 17, 2016
    b291998
  5. serhiy-storchaka commented on Mar 21, 2016

    @serhiy-storchaka
    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').

  6. gvanrossum commented on Mar 21, 2016

    @gvanrossum
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions