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

Terry Reedy tjreedy at udel.edu
Wed Mar 16 11:59:16 EDT 2016

On 3/16/2016 3:14 AM, Serhiy Storchaka wrote:
> On 16.03.16 02:28, Guido van Rossum wrote:
>> I agree that the spirit of the PEP is to stop at the first coding
>> cookie found. Would it be okay if I updated the PEP to clarify this?
>> I'll definitely also update the docs.
> Could you please also update the regular expression in PEP 263 to
> "^[ \t\v]*#.*?coding[:=][ \t]*([-.a-zA-Z0-9]+)"?
> Coding cookie must be in comment, only the first occurrence in the line
> must be taken to account (here is a bug in CPython), encoding name must
> be ASCII, and there must not be any Python statement on the line that
> contains the encoding declaration. [1]
> [1] https://bugs.python.org/issue18873

Also, I think there should be one 'official' function somewhere in the 
stdlib to get and return the encoding declaration. The patch for the 
issue above had to make the same change in four places other than tests, 
a violent violation of DRY.

Terry Jan Reedy

More information about the Python-Dev mailing list