I've been trying to understand the problem here. The cause is easy to explain, for the cure I would like to consult the savvy before PR'ing.
The cause: * Parsing of '<...>' will instantiate a typecast from a basetype node and a declarator node, then the typecast type will be inferred from these two nodes. * ParseTreeTransform of 'cast(....)' will instead instantiate a typecast node directly from a type (parsed as 'sizeof(...)'). So there will be no self.base_type in this part of TypecastNode.analyse_types: if to_py and not from_py: .... elif self.operand.type.can_coerce_to_pyobject(env): self.result_ctype = py_object_type base_type = self.base_type.analyse(env) self.operand = self.operand.coerce_to(base_type, env) .... The question: Why isn't the last line simply "self.operand = self.operand.coerce_to(self.type, env)"? That is, what's the point of coercing to the base type here instead of coercing to the type itself? A fortiori, notice this is inside the to_py case, I'm not even sure that base_type makes sense here. For example: - Pointer base type cannot be a Python object (for <A*>). - Const base type cannot be a Python object (for <const A>). - Cannot cast to a function type (for <A()>). (the compiler dixit) Cheers -- Carlos On Fri, Oct 16, 2015 at 4:05 PM, Carlos Pita <carlosjosep...@gmail.com> wrote: > Hi, > > import cython as cy > y = cy.cast('list', x) > > fails to compile with "AttributeError: 'TypecastNode' object has no > attribute 'typecheck'". > > But the following examples do compile: > > y = <list> x > > y = cy.cast('int', x) > > Cheers > -- > Carlos > >
_______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel