cython-devel

changeset 904:8b22ff3db9f7

Public extension type properties working from pxd

The issue was that pxd files don't get transformed yet.
author Robert Bradshaw <robertwb@math.washington.edu>
date Sat Aug 02 19:16:28 2008 -0700 (4 years ago)
parents 6a8548429322
children 624d0463d407
files Cython/Compiler/Nodes.py Cython/Compiler/ParseTreeTransforms.py tests/errors/e_extmember.pyx tests/run/extmember.pyx
line diff
1.1 --- a/Cython/Compiler/Nodes.py Sat Aug 02 17:40:02 2008 -0700 1.2 +++ b/Cython/Compiler/Nodes.py Sat Aug 02 19:16:28 2008 -0700 1.3 @@ -672,6 +672,7 @@ 1.4 cname = cname, visibility = visibility, is_cdef = 1) 1.5 if need_property: 1.6 self.need_properties.append(entry) 1.7 + entry.needs_property = 1 1.8 1.9 1.10 class CStructOrUnionDefNode(StatNode): 1.11 @@ -979,7 +980,7 @@ 1.12 self.put_stararg_decrefs(code) 1.13 if acquire_gil: 1.14 code.putln("PyGILState_Release(_save);") 1.15 - code.putln("/* TODO: decref scope object */") 1.16 + # code.putln("/* TODO: decref scope object */") 1.17 # ----- Return 1.18 if not self.return_type.is_void: 1.19 code.putln("return %s;" % Naming.retval_cname) 1.20 @@ -2116,6 +2117,15 @@ 1.21 1.22 if self.doc and Options.docstrings: 1.23 scope.doc = embed_position(self.pos, self.doc) 1.24 + 1.25 + if has_body and not self.in_pxd: 1.26 + # transforms not yet run on pxd files 1.27 + from ParseTreeTransforms import AnalyseDeclarationsTransform 1.28 + transform = AnalyseDeclarationsTransform(None) 1.29 + for entry in scope.var_entries: 1.30 + if hasattr(entry, 'needs_property'): 1.31 + property = transform.create_Property(entry) 1.32 + self.body.stats.append(property) 1.33 1.34 if has_body: 1.35 self.body.analyse_declarations(scope)
2.1 --- a/Cython/Compiler/ParseTreeTransforms.py Sat Aug 02 17:40:02 2008 -0700 2.2 +++ b/Cython/Compiler/ParseTreeTransforms.py Sat Aug 02 19:16:28 2008 -0700 2.3 @@ -339,16 +339,22 @@ 2.4 # mechanism for them. 2.5 stats = [] 2.6 for entry in node.need_properties: 2.7 - property = self.basic_property.substitute({ 2.8 - u"ATTR": AttributeNode(pos=entry.pos, obj=NameNode(pos=entry.pos, name="self"), attribute=entry.name), 2.9 - }, pos=entry.pos) 2.10 - property.stats[0].name = entry.name 2.11 + property = self.create_Property(entry) 2.12 property.analyse_declarations(node.dest_scope) 2.13 self.visit(property) 2.14 stats.append(property) 2.15 return StatListNode(pos=node.pos, stats=stats) 2.16 else: 2.17 return None 2.18 + 2.19 + def create_Property(self, entry): 2.20 + property = self.basic_property.substitute({ 2.21 + u"ATTR": AttributeNode(pos=entry.pos, 2.22 + obj=NameNode(pos=entry.pos, name="self"), 2.23 + attribute=entry.name), 2.24 + }, pos=entry.pos).stats[0] 2.25 + property.name = entry.name 2.26 + return property 2.27 2.28 class AnalyseExpressionsTransform(CythonTransform): 2.29 def visit_ModuleNode(self, node):
3.1 --- a/tests/errors/e_extmember.pyx Sat Aug 02 17:40:02 2008 -0700 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,5 +0,0 @@ 3.4 -cdef class Spam: 3.5 - cdef public Spam e 3.6 -_ERRORS = u""" 3.7 -/Local/Projects/D/Pyrex/Source/Tests/Errors1/e_extmember.pyx:2:18: Non-generic Python attribute cannot be exposed for writing from Python 3.8 -"""
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tests/run/extmember.pyx Sat Aug 02 19:16:28 2008 -0700 4.3 @@ -0,0 +1,13 @@ 4.4 +__doc__ = """ 4.5 + >>> s = Spam() 4.6 + >>> s.e = s 4.7 + >>> s.e = 1 4.8 + Traceback (most recent call last): 4.9 + TypeError: Cannot convert int to extmember.Spam 4.10 + >>> s.e is s 4.11 + True 4.12 + >>> s.e = None 4.13 +""" 4.14 + 4.15 +cdef class Spam: 4.16 + cdef public Spam e