[New-bugs-announce] [issue22221] ast.literal_eval confused by coding declarations

Jorgen Schäfer report at bugs.python.org
Sun Aug 17 21:53:49 CEST 2014


New submission from Jorgen Schäfer:

The ast module seems to get confused for certain strings which contain coding declarations.

>>> import ast

>>> s = u'"""\\\n# -*- coding: utf-8 -*-\n"""'
>>> print s
"""\
# -*- coding: utf-8 -*-
"""
>>> ast.literal_eval(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/forcer/Programs/Python/python2.7/lib/python2.7/ast.py", line 49, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/home/forcer/Programs/Python/python2.7/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 0
SyntaxError: encoding declaration in Unicode string

----------
components: Library (Lib)
messages: 225464
nosy: jorgenschaefer
priority: normal
severity: normal
status: open
title: ast.literal_eval confused by coding declarations
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22221>
_______________________________________


More information about the New-bugs-announce mailing list