Message6327

Author pjenvey
Recipients jpulakka, pjenvey
Date 2011-01-20.00:13:24
SpamBayes Score 1.0163714e-10
Marked as misclassified No
Message-id <1295482405.12.0.513529808992.issue1696@psf.upfronthosting.co.za>
In-reply-to
Content
Ok, you have encountered a minor issue with PythonInterpreter.exec(String). It should be acting like compile(unicode), which would reject your example with a SyntaxError because it includes a magic encoding comment. From PEP 263:

The builtin compile() API will be enhanced to accept Unicode as
    input. 8-bit string input is subject to the standard procedure for
    encoding detection as described above.

    If a Unicode string with a coding declaration is passed to compile(),
    a SyntaxError will be raised.

It should be rejected because it doesn't make sense to tell the parser how to decode source code that's already decoded. The magic encoding comment is only applicable to encoded data (like plain Python strs or Java bytes)

We do raise a SyntaxError here in accordance with the PEP, but I'll leave this issue open because as our SyntaxError message doesn't make the issue clear. It should match CPython's:

Python 2.6.4 (r264:75706, Dec  8 2009, 15:56:45) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> compile(u'# coding: utf-8\n', '<file>', 'exec')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<file>", line 0
SyntaxError: encoding declaration in Unicode string
History
Date User Action Args
2011-01-20 00:13:25pjenveysetmessageid: <1295482405.12.0.513529808992.issue1696@psf.upfronthosting.co.za>
2011-01-20 00:13:25pjenveysetrecipients: + pjenvey, jpulakka
2011-01-20 00:13:25pjenveylinkissue1696 messages
2011-01-20 00:13:24pjenveycreate