From: Robert Collins Date: Thu, 6 Aug 2015 09:08:44 +0000 (+1200) Subject: Issue #24531: Document that encoding lines cannot follow non-comment lines. X-Git-Tag: v2.7.11rc1~200 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=311c8d63e581b29a9a086a318d5265d0c124cec5;p=thirdparty%2FPython%2Fcpython.git Issue #24531: Document that encoding lines cannot follow non-comment lines. Patch from Terry Reedy --- diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 52a09a895c66..94b003c5c44c 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -109,7 +109,9 @@ Encoding declarations If a comment in the first or second line of the Python script matches the regular expression ``coding[=:]\s*([-\w.]+)``, this comment is processed as an encoding declaration; the first group of this expression names the encoding of -the source code file. The recommended forms of this expression are :: +the source code file. The encoding declaration must appear on a line of its +own. If it is the second line, the first line must also be a comment-only line. +The recommended forms of an encoding expression are :: # -*- coding: -*- @@ -126,8 +128,7 @@ If an encoding is declared, the encoding name must be recognized by Python. The encoding is used for all lexical analysis, in particular to find the end of a string, and to interpret the contents of Unicode literals. String literals are converted to Unicode for syntactical analysis, then converted back to their -original encoding before interpretation starts. The encoding declaration must -appear on a line of its own. +original encoding before interpretation starts. .. XXX there should be a list of supported encodings.