Hello,

I have started using Cython recently to spped up some Python code; it
works very well and stably, but today I managed to crash Cython 0.11
while trying to compile the following pure Python code:

  # iter.py
  class Iter(object):

      """A docstring."""

      def __iter__(self):
          return self

      def __next__(self):
          raise StopIteration

I'm augmenting the pure Python code with the following .pxd file::

  # iter.pxd
  cpdef class Iter(object)

The Cython-0.11 invocation "cython iter.py" dies with the following backtrace::

  $ cython iter.py

  Error converting Pyrex file to C:
  ------------------------------------------------------------
  ...
  class Iter(object):

      """A docstring."""

      def __iter__(self):
     ^
  ------------------------------------------------------------

  /tmp/iter.py:5:4: Compiler crash in AlignFunctionDefinitions

  ModuleNode.body = StatListNode(iter.py:1:0)
  StatListNode.stats[0] = PyClassDefNode(iter.py:1:0,
      doc = 'A docstring.',
      name = u'Iter')
  CClassDefNode.body = StatListNode(iter.py:5:4)
  StatListNode.stats[0] = DefNode(iter.py:5:4,
      name = u'__iter__',
      num_required_args = 1,
      reqd_kw_flags_cname = '0')

  Compiler crash traceback from this point on:
    File "Visitor.py", line 149, in Cython.Compiler.Visitor.visitchild
(/home/rmurri/phd.cython/src/Cython-0.11/Cython/Compiler/Visitor.c:2814)
    File "Visitor.py", line 45, in
Cython.Compiler.Visitor.BasicVisitor.visit
(/home/rmurri/phd.cython/src/Cython-0.11/Cython/Compiler/Visitor.c:1356)
    File 
"/home/rmurri/phd.cython/src/Cython-0.11/Cython/Compiler/ParseTreeTransforms.py",
line 788, in visit_DefNode
      pxd_def = self.scope.lookup(node.name)
  AttributeError: 'NoneType' object has no attribute 'lookup'


Compilation is fine if I merge the .pxd and the .py into a .pyx::

  cpdef class Iter(object):

      """A docstring."""

      def __iter__(self):
          return self

      def __next__(self):
          raise StopIteration


Best regards,
Riccardo


-- 
Riccardo Murri, via Rossée 17, 6987 Caslano (CH)
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to