[Python-Dev] What does a double coding cookie mean?

Guido van Rossum guido at python.org
Wed Mar 16 20:05:32 EDT 2016


On Wed, Mar 16, 2016 at 12:59 AM, M.-A. Lemburg <mal at egenix.com> wrote:
> The only reason to read up to two lines was to address the use of
> the shebang on Unix, not to be able to define two competing
> source code encodings :-)

I know. I was just surprised that the PEP was sufficiently vague about
it that when I found that mypy picked the second if there were two, I
couldn't prove to myself that it was violating the PEP. I'd rather
clarify the PEP than rely on the reasoning presented earlier here.

I don't like erroring out when there are two different cookies on two
lines; I feel that the spirit of the PEP is to read up to two lines
until a cookie is found, whichever comes first.

I will update the regex in the PEP too (or change the wording to avoid "match").

I'm not sure what to do if there are two cooking on one line. If
CPython currently picks the latter we may want to preserve that
behavior.

Should we recommend that everyone use tokenize.detect_encoding()?

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list