[Python-projects] astng crashes on yield expression

Huurne, Maarten ter maarten.ter.huurne at philips.com
Thu Mar 26 18:54:53 CET 2009


Hi,

Please consider this program:
===
def f():
                yield 45
                x = yield 123
===

When running pylint on it, it crashes with this backtrace:
===
Traceback (most recent call last):
  File "/usr/bin/pylint", line 4, in <module>
    lint.Run(sys.argv[1:])
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 881, in __init__
    linter.check(args)
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 500, in check
    self.check_astng_module(astng, checkers)
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 577, in check_astng_module
    if implements(checker, IASTNGChecker)])
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 594, in astng_events
    self.astng_events(child, checkers, _reversed_checkers)
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 594, in astng_events
    self.astng_events(child, checkers, _reversed_checkers)
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 594, in astng_events
    self.astng_events(child, checkers, _reversed_checkers)
  File "/usr/lib/python2.5/site-packages/pylint/lint.py", line 591, in astng_events
    checker.visit(astng)
  File "/usr/lib/python2.5/site-packages/logilab/astng/utils.py", line 320, in visit
    method(node)
  File "/usr/lib/python2.5/site-packages/pylint/checkers/format.py", line 267, in visit_default
    prev_sibl = node.previous_sibling()
  File "/usr/lib/python2.5/site-packages/logilab/astng/nodes.py", line 251, in previous_sibling
    stmts = self.parent.child_sequence(self)
  File "/usr/lib/python2.5/site-packages/logilab/astng/nodes.py", line 216, in child_sequence
    raise ASTNGError(msg % (repr(child), repr(self)))
logilab.astng._exceptions.ASTNGError: Could not found <_ast.Yield object at 0x1034890> in <_ast.Assign object at 0x1034810>'s children
 ===

In previous_sibling(), the Yield node is looked up in its parent. That works for line 2 where yield is used as a statement, but fails for line 3 where yield is used as an expression.

The _ast module always considers yield an expression (both for the line 2 and line 3 case). Taking that as inspiration, I moved "Yield" from STMT_NODES to ALL_NODES in "nodes.py" in astng. That fixes the crash, but I don't know if there is other code that will break when "yield" is never considered a statement.

By the way, the docstring of previous_sibling() looks like it belongs with next_sibling() and vice versa.

Bye,
                                Maarten


________________________________
The information contained in this message may be confidential and legally protected under applicable law. The message is intended solely for the addressee(s). If you are not the intended recipient, you are hereby notified that any use, forwarding, dissemination, or reproduction of this message is strictly prohibited and may be unlawful. If you are not the intended recipient, please contact the sender by return e-mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.logilab.org/pipermail/python-projects/attachments/20090326/68ede6b1/attachment.htm>


More information about the Python-Projects mailing list