[ python-Bugs-898757 ] Python 2.3 encoding parsing bug

SourceForge.net noreply at sourceforge.net
Tue Feb 17 16:14:06 EST 2004


Bugs item #898757, was opened at 2004-02-17 15:36
Message generated for change (Comment added) made by lemburg
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=898757&group_id=5470

Category: Parser/Compiler
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Edward K. Ream (edream)
Assigned to: Nobody/Anonymous (nobody)
Summary: Python 2.3 encoding parsing bug

Initial Comment:
The documentation for encoding lines at

C:\Python23\Doc\Python-Docs-2.3.1\whatsnew\section-
encodings.html

states:

"Encodings are declared by including a specially 
formatted comment in the first or second line of the 
source file."

In fact, contrary to the implication, the Python 2.3 
parser does not look for lines of the form:

# -*- coding: <encoding> -*-

For example, Python improperly scans the following line 
for an encoding

#@+leo-ver=4-encoding=iso-8859-1.

and reports that iso-8859-1. (note trailing dot) is an 
invalid encoding!

The workaround for my app is to precede this line with 
the following line:

# -*- coding: iso-8859-1 -*-

This makes Python 2.3 happy.

To make myself perfectly clear: Python has absolutely 
no right to complain about comment lines that do not 
have the form:

# -*- coding: <encoding> -*-

Python 2.3.1
Windows XP

Edward K. Ream
edreamleo at charter.net

----------------------------------------------------------------------

>Comment By: M.-A. Lemburg (lemburg)
Date: 2004-02-17 22:14

Message:
Logged In: YES 
user_id=38388

Python is behaving correctly and according to the PEP.

The encoding declaration parser will look for "coding[:=][
\t]*<encoding>"
to make it play nice with various different editor encoding
comments
in use today. The format you are quoting is Emacs-style, but
there are also vi-style and various other formats. Most of them
use the "coding[:=]" declaration which is why this parsing
method
was chosen.

Does leo need the trailing dot in the comment ?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=898757&group_id=5470



More information about the Python-bugs-list mailing list