[New-bugs-announce] [issue15846] literal_eval raises SystemError instead of SyntaxError, because of illegal escape sequence

David Halter report at bugs.python.org
Sun Sep 2 10:46:06 CEST 2012


New submission from David Halter:

Hi! I'm the developer of Jedi: https://github.com/davidhalter/jedi, which is an auto-completion library. I try to support Python 2.5-3.2.
The bug just appears in Python 3.2.

Parsing string literals with literal_eval works normally without a problem, but in this certain constellation, it raises a SystemError (instead of a SyntaxError).

The error line is simple:
literal_eval(r"'\U'")

But: It only raises the error in that particular place:
https://github.com/davidhalter/jedi/blob/master/parsing.py#L157

To try and test it:

git clone git://github.com/davidhalter/jedi.git
cd jedi
# uncomment the line after TODO in parsing.Scope.add_docstr
python3 test/run.py array

The error message:

Traceback (most recent call last):
  File "./run.py", line 51, in run_definition_test
    result = defs(line_nr, len(line))
  File "./run.py", line 49, in defs
    return set(functions.get_definitions(source, line_nr, indent, path))
  File "./functions.py", line 253, in get_definitions
    scopes = _prepare_goto(source, pos, source_path, f, goto_path)
  File "./functions.py", line 227, in _prepare_goto
    scopes = evaluate.follow_statement(stmt)
  File "./helpers.py", line 23, in __call__
    if self.push_stmt(stmt):
  File "./helpers.py", line 31, in push_stmt
    self.current = RecursionNode(stmt, self.current)
  File "./helpers.py", line 75, in __init__
    or (self.script == builtin.Builtin.scope)
  File "./builtin.py", line 408, in scope
    return self._builtins.parser.module
  File "./builtin.py", line 42, in parser
    self._load_module()
  File "./builtin.py", line 50, in _load_module
    self._parser = parsing.PyFuzzyParser(source, self.path or self.name)
  File "./parsing.py", line 1047, in __init__
    self.parse()
  File "./parsing.py", line 1600, in parse
    stmt, tok = self._parse_statement(self.current)
  File "./parsing.py", line 1386, in _parse_statement
    self.scope.add_docstr(self.last_token[1])
  File "./parsing.py", line 157, in add_docstr
    literal_eval(r"'\U'")
  File "/usr/lib/python3.2/ast.py", line 48, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python3.2/ast.py", line 36, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
SystemError: ../Objects/tupleobject.c:126: bad argument to internal function

Cheers!
David

----------
messages: 169687
nosy: davidhalter
priority: normal
severity: normal
status: open
title: literal_eval raises SystemError instead of SyntaxError, because of illegal escape sequence
versions: Python 3.2

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


More information about the New-bugs-announce mailing list