[Python-checkins] peps: Clarify things around the coding cookie.

guido.van.rossum python-checkins at python.org
Wed Mar 16 20:20:22 EDT 2016


https://hg.python.org/peps/rev/22490711c870
changeset:   6253:22490711c870
user:        Guido van Rossum <guido at python.org>
date:        Wed Mar 16 17:19:40 2016 -0700
summary:
  Clarify things around the coding cookie.

Serhiy Storchaka: "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."

files:
  pep-0263.txt |  6 ++++--
  1 files changed, 4 insertions(+), 2 deletions(-)


diff --git a/pep-0263.txt b/pep-0263.txt
--- a/pep-0263.txt
+++ b/pep-0263.txt
@@ -61,11 +61,13 @@
           # vim: set fileencoding=<encoding name> :
 
     More precisely, the first or second line must match the regular
-    expression "coding[:=]\s*([-\w.]+)". The first group of this
+    expression "^[ \t\v]*#.*?coding[:=][ \t]*([-.a-zA-Z0-9]+)".
+    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.
+    encoding declaration.  If the first line matches the second line
+    is ignored.
 
     To aid with platforms such as Windows, which add Unicode BOM marks
     to the beginning of Unicode files, the UTF-8 signature

-- 
Repository URL: https://hg.python.org/peps


More information about the Python-checkins mailing list