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."
This commit is contained in:
Guido van Rossum 2016-03-16 17:19:40 -07:00
parent cbf79d2711
commit e8c05569ec
1 changed files with 4 additions and 2 deletions

View File

@ -61,11 +61,13 @@ Defining the Encoding
# vim: set fileencoding=<encoding name> : # vim: set fileencoding=<encoding name> :
More precisely, the first or second line must match the regular 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 expression is then interpreted as encoding name. If the encoding
is unknown to Python, an error is raised during compilation. There is unknown to Python, an error is raised during compilation. There
must not be any Python statement on the line that contains the 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 aid with platforms such as Windows, which add Unicode BOM marks
to the beginning of Unicode files, the UTF-8 signature to the beginning of Unicode files, the UTF-8 signature