[Python-Dev] PEP 263 -- Python Source Code Encoding

Martin v. Loewis martin@v.loewis.de
27 Feb 2002 22:01:25 +0100

Skip Montanaro <skip@pobox.com> writes:

>     >> Perhaps a warning should be emitted by the compiler if a plain string
>     >> literal is found that contains 8-bit characters.  Better yet, perhaps
>     >> Neal can add this to PyChecker if he hasn't already...
>     mal> See the PEP: this is what phase 1 will do; phase 2 won't accept
>     mal> such a file without an explicit encoding declaration.
> That wasn't what I was getting at.  The quoted part of the reference manual
> seemed to suggest that programmers should be using hex escapes in string
> literals instead of 8-bit characters.  This doesn't seem to me to be related
> to what encoding the file is in.

PEP 263 says "the tokenizer must check the complete source file for
compliance with the default encoding". The part of the reference
manual will become incorrect: the meaning of 8-bit characters (rather:
bytes) will be well-defined if you have an encoding declaration.

If the default encoding is ASCII, and you have a 8-bit character, the
compiler will emit a warning if it is enhanced to follow PEP 263. So
what were you getting at?