Commit 6501e274 authored by Robert Bradshaw's avatar Robert Bradshaw

Allow pure python annotations in type declarations.

Related to #1838.
parent 131f7fd0
......@@ -632,7 +632,7 @@ class TrackNumpyAttributes(VisitorTransform, SkipDeclarations):
visit_Node = VisitorTransform.recurse_to_children
class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
class InterpretCompilerDirectives(CythonTransform):
"""
After parsing, directives can be stored in a number of places:
- #cython-comments at the top of the file (stored in ModuleNode)
......@@ -857,6 +857,11 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
node.cython_attribute = directive
return node
def visit_NewExprNode(self, node):
self.visit(node.cppclass)
self.visitchildren(node)
return node
def try_to_parse_directives(self, node):
# If node is the contents of an directive (in a with statement or
# decorator), returns a list of (directivename, value) pairs.
......@@ -987,7 +992,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
def visit_CVarDefNode(self, node):
directives = self._extract_directives(node, 'function')
if not directives:
return node
return self.visit_Node(node)
for name, value in directives.items():
if name == 'locals':
node.directive_locals = value
......
# tag: cpp
cimport cython
from cython.operator import dereference as deref
cdef extern from "cpp_templates_helper.h":
......@@ -148,3 +149,16 @@ def test_static(x):
(1, 1.5)
"""
return Div[int].half(x), Div[double].half(x)
def test_pure_syntax(int i):
"""
>>> test_ptr(3)
3
>>> test_ptr(5)
5
"""
try:
w = new Wrap[cython.pointer(int)](&i)
return deref(w.get())
finally:
del w
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment