Proposal: require 7-bit source str's

"Martin v. Löwis" martin at v.loewis.de
Fri Aug 6 05:47:15 EDT 2004


Hallvard B Furuseth wrote:
>>The coding declaration was only acceptable because
>>- a statement would have to go before the doc string, in
>>   which case it would not have been a docstring anymore, and
> 
> 
> Hmm...

You misunderstood. I was talking about the module docstring

"Written by Martin v. Löwis"
directive encoding "utf-8"

Here, the declaration comes after the first non-ASCII character,
which does not work.

directive encoding "utf-8"
"Written by Martin v. Löwis"

Here, the string is not a docstring anymore, because it is
not the first expression in the module.

>   >>> help(bar)
>   Traceback (most recent call last):
>     ...
>   UnicodeEncodeError: 'ascii' codec can't encode character '\uf8'
>   in position 59: ordinal not in range(128)

That's a bug in the help function.

> Even if the doc string is written in English, it may still need to
> use non-English names.

Certainly. This is why the encoding declaration can't be a statement.

> Still, how about 'directive str7bit', 'directive -W::str7bitWarning' or
> something?

See PEP 244. I would have liked a directive statement, but the PEP was
rejected (in favour of __future__ imports, at that time).

A future import might work, except that this is a commitment that
the future comes some day, which, for str7bit, would not be the case:
there will *always* be a possibility to put non-ASCII bytes into 8-bit
strings (of course, requiring that people use escape sequences for
them might be acceptable).

In any case, you probably have to write a PEP for this.

Regards,
Martin



More information about the Python-list mailing list