Commit 459f11b4 authored by Robert Bradshaw's avatar Robert Bradshaw

Public extension type properties working from pxd

The issue was that pxd files don't get transformed yet.

--HG--
rename : tests/errors/e_extmember.pyx => tests/run/extmember.pyx
parent 25612694
...@@ -672,6 +672,7 @@ class CVarDefNode(StatNode): ...@@ -672,6 +672,7 @@ class CVarDefNode(StatNode):
cname = cname, visibility = visibility, is_cdef = 1) cname = cname, visibility = visibility, is_cdef = 1)
if need_property: if need_property:
self.need_properties.append(entry) self.need_properties.append(entry)
entry.needs_property = 1
class CStructOrUnionDefNode(StatNode): class CStructOrUnionDefNode(StatNode):
...@@ -979,7 +980,7 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -979,7 +980,7 @@ class FuncDefNode(StatNode, BlockNode):
self.put_stararg_decrefs(code) self.put_stararg_decrefs(code)
if acquire_gil: if acquire_gil:
code.putln("PyGILState_Release(_save);") code.putln("PyGILState_Release(_save);")
code.putln("/* TODO: decref scope object */") # code.putln("/* TODO: decref scope object */")
# ----- Return # ----- Return
if not self.return_type.is_void: if not self.return_type.is_void:
code.putln("return %s;" % Naming.retval_cname) code.putln("return %s;" % Naming.retval_cname)
...@@ -2117,6 +2118,15 @@ class CClassDefNode(ClassDefNode): ...@@ -2117,6 +2118,15 @@ class CClassDefNode(ClassDefNode):
if self.doc and Options.docstrings: if self.doc and Options.docstrings:
scope.doc = embed_position(self.pos, self.doc) scope.doc = embed_position(self.pos, self.doc)
if has_body and not self.in_pxd:
# transforms not yet run on pxd files
from ParseTreeTransforms import AnalyseDeclarationsTransform
transform = AnalyseDeclarationsTransform(None)
for entry in scope.var_entries:
if hasattr(entry, 'needs_property'):
property = transform.create_Property(entry)
self.body.stats.append(property)
if has_body: if has_body:
self.body.analyse_declarations(scope) self.body.analyse_declarations(scope)
if self.in_pxd: if self.in_pxd:
......
...@@ -339,10 +339,7 @@ property NAME: ...@@ -339,10 +339,7 @@ property NAME:
# mechanism for them. # mechanism for them.
stats = [] stats = []
for entry in node.need_properties: for entry in node.need_properties:
property = self.basic_property.substitute({ property = self.create_Property(entry)
u"ATTR": AttributeNode(pos=entry.pos, obj=NameNode(pos=entry.pos, name="self"), attribute=entry.name),
}, pos=entry.pos)
property.stats[0].name = entry.name
property.analyse_declarations(node.dest_scope) property.analyse_declarations(node.dest_scope)
self.visit(property) self.visit(property)
stats.append(property) stats.append(property)
...@@ -350,6 +347,15 @@ property NAME: ...@@ -350,6 +347,15 @@ property NAME:
else: else:
return None return None
def create_Property(self, entry):
property = self.basic_property.substitute({
u"ATTR": AttributeNode(pos=entry.pos,
obj=NameNode(pos=entry.pos, name="self"),
attribute=entry.name),
}, pos=entry.pos).stats[0]
property.name = entry.name
return property
class AnalyseExpressionsTransform(CythonTransform): class AnalyseExpressionsTransform(CythonTransform):
def visit_ModuleNode(self, node): def visit_ModuleNode(self, node):
node.body.analyse_expressions(node.scope) node.body.analyse_expressions(node.scope)
......
cdef class Spam:
cdef public Spam e
_ERRORS = u"""
/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_extmember.pyx:2:18: Non-generic Python attribute cannot be exposed for writing from Python
"""
__doc__ = """
>>> s = Spam()
>>> s.e = s
>>> s.e = 1
Traceback (most recent call last):
TypeError: Cannot convert int to extmember.Spam
>>> s.e is s
True
>>> s.e = None
"""
cdef class Spam:
cdef public Spam e
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