Commit 3822c930 authored by Robert Bradshaw's avatar Robert Bradshaw

Merge pull request #458 from memeplex/feat/pubattrs

Add visibility kwarg to cython.declare.
parents 2153b115 4d7f6c48
......@@ -4833,12 +4833,18 @@ class SingleAssignmentNode(AssignmentNode):
func_name = self.rhs.function.as_cython_attribute()
if func_name:
args, kwds = self.rhs.explicit_args_kwds()
if func_name in ['declare', 'typedef']:
if len(args) > 2 or kwds is not None:
error(self.rhs.pos, "Can only declare one type at a time.")
if len(args) > 2:
error(args[2].pos, "Invalid positional argument.")
return
if kwds is not None:
kwdict = kwds.compile_time_value(None)
if func_name == 'typedef' or 'visibility' not in kwdict:
error(kwds.pos, "Invalid keyword argument.")
return
visibility = kwdict['visibility']
else:
visibility = 'private'
type = args[0].analyse_as_type(env)
if type is None:
error(args[0].pos, "Unknown type")
......@@ -4853,7 +4859,7 @@ class SingleAssignmentNode(AssignmentNode):
error(lhs.pos, "Invalid declaration")
return
for var, pos in vars:
env.declare_var(var, type, pos, is_cdef = True)
env.declare_var(var, type, pos, is_cdef=True, visibility=visibility)
if len(args) == 2:
# we have a value
self.rhs = args[1]
......
......@@ -176,6 +176,15 @@ Static typing
self.a = 3
self.b = b
And even to define extension type private, readonly and public attributes::
@cython.cclass
class A:
cython.declare(a=cython.int, b=cython.int)
c = cython.declare(cython.int, visibility='public')
d = cython.declare(cython.int, 5) # private by default.
e = cython.declare(cython.int, 5, visibility='readonly')
* ``@cython.locals`` is a decorator that is used to specify the types of local
variables in the function body (including the arguments)::
......
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