<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#330033">
    <div class="moz-cite-prefix">On 3/15/2016 11:07 PM, Chris Angelico
      wrote:<br>
    </div>
    <blockquote
cite="mid:CAPTjJmpoWh2uTFPrA8S2G8GF7t+9_V19Kt=_qkhu6F--Et3beg@mail.gmail.com"
      type="cite">
      <pre wrap="">On Wed, Mar 16, 2016 at 5:03 PM, Serhiy Storchaka <a class="moz-txt-link-rfc2396E" href="mailto:storchaka@gmail.com"><storchaka@gmail.com></a> wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">On 15.03.16 22:30, Guido van Rossum wrote:
</pre>
        <blockquote type="cite">
          <pre wrap="">
I came across a file that had two different coding cookies -- one on
the first line and one on the second. CPython uses the first, but mypy
happens to use the second. I couldn't find anything in the spec or
docs ruling out the second interpretation. Does anyone have a
suggestion (apart from following CPython)?

Reference: <a class="moz-txt-link-freetext" href="https://github.com/python/mypy/issues/1281">https://github.com/python/mypy/issues/1281</a>
</pre>
        </blockquote>
        <pre wrap="">

There is similar question. If a file has two different coding cookies on the
same line, what should win? Currently the last cookie wins, in CPython
parser, in the tokenize module, in IDLE, and in number of other code. I
think this is a bug.
</pre>
      </blockquote>
      <pre wrap="">
Why would you ever have two coding cookies in a file? Surely this
should be either an error, or ill-defined (ie parsers are allowed to
pick whichever they like, including raising)?

ChrisA
</pre>
    </blockquote>
    <br>
    From the PEP 263:<br>
    <br>
    <blockquote type="cite">To define a source code encoding, a magic
      comment must<br>
          be placed into the source files either as first or second<br>
          line in the file, such as:</blockquote>
    <br>
    So clearly there is only one magic comment. "either" the first or
    second line, not both.  Both, therefore, should be an error.<br>
    <br>
    <br>
    From the PEP 263:<br>
    <br>
    <blockquote type="cite">More precisely, the first or second line
      must match the regular<br>
          expression "coding[:=]\s*([-\w.]+)". The first group of this<br>
          expression is then interpreted as encoding name. If the
      encoding<br>
          is unknown to Python, an error is raised during compilation.
      There<br>
          must not be any Python statement on the line that contains the<br>
          encoding declaration.</blockquote>
    <br>
    Clearly the regular expression would only match the first of
    multiple cookies on the same line, so the first one should always
    win... but there should only be one, from the first PEP quote "a
    magic comment".<br>
    <br>
    Glenn<br>
  </body>
</html>