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

Glenn Linderman v+python at g.nevcal.com
Wed Mar 16 03:46:04 EDT 2016

On 3/16/2016 12:09 AM, Serhiy Storchaka wrote:
> On 16.03.16 08:34, Glenn Linderman wrote:
>>  From the PEP 263:
>>> More precisely, the first or second line must match the regular
>>>     expression "coding[:=]\s*([-\w.]+)". The first group of this
>>>     expression is then interpreted as encoding name. If the encoding
>>>     is unknown to Python, an error is raised during compilation. There
>>>     must not be any Python statement on the line that contains the
>>>     encoding declaration.
>> 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".
> "The first group of this expression" means the first regular 
> expression group. Only the part between parenthesis "([-\w.]+)" is 
> interpreted as encoding name, not all expression.

Sure.  But there is no mention anywhere in the PEP of more than one 
being legal: just more than one position for it, EITHER line 1 or line 
2. So while the regular expression mentioned is not anchored, to allow 
variation in syntax between emacs and vim, "must match the regular 
expression" doesn't imply "several times", and when searching for a 
regular expression that might not be anchored, one typically expects to 
find the first.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160316/4b4c1e8a/attachment.html>

More information about the Python-Dev mailing list