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

Stephen J. Turnbull stephen at xemacs.org
Sat Mar 19 14:03:37 EDT 2016

Glenn Linderman writes:
 > On 3/19/2016 8:19 AM, Serhiy Storchaka wrote:

 > > Therefore current CPython behavior can be correct, and the regular 
 > > expression in PEP 263 should be changed to use greedy repetition.
 > Just because emacs works that way (and even though I'm an emacs user), 
 > that doesn't mean CPython should act like emacs.
 > (1) CPython should not necessarily act like emacs,

We can't treat Emacs as a spec, because Emacs doesn't follow specs,
doesn't respect standards, and above a certain level of inconvenience
to developers doesn't respect backward compatibility.  There's never
any guarantee that Emacs will do the same thing tomorrow that it does
today, although inertia has mostly the same effect.

In this case, there's a reason why Emacs behaves the way it does,
which is that you can put an arbitrary sequence of variable
assignments in "-*- ... -*-" and they will be executed in order.  So
it makes sense that "last coding wins".  But pragmas are severely
deprecated in Python; cookies got a very special exception.  So that
rationale can't apply to Python.

 > (4) there is no benefit to specifying the coding twice on a line, it 
 > only adds confusion, whether in CPython, emacs, or vim.

Indeed.  I see no point in reading past the first cookie found
(whether a valid codec or not), unless an error would be raised.  That
might be a good idea, but I doubt it's worth the implementation

More information about the Python-Dev mailing list