Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
3822c930
Commit
3822c930
authored
Mar 10, 2016
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #458 from memeplex/feat/pubattrs
Add visibility kwarg to cython.declare.
parents
2153b115
4d7f6c48
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+11
-5
docs/src/tutorial/pure.rst
docs/src/tutorial/pure.rst
+9
-0
No files found.
Cython/Compiler/Nodes.py
View file @
3822c930
...
@@ -4833,12 +4833,18 @@ class SingleAssignmentNode(AssignmentNode):
...
@@ -4833,12 +4833,18 @@ class SingleAssignmentNode(AssignmentNode):
func_name
=
self
.
rhs
.
function
.
as_cython_attribute
()
func_name
=
self
.
rhs
.
function
.
as_cython_attribute
()
if
func_name
:
if
func_name
:
args
,
kwds
=
self
.
rhs
.
explicit_args_kwds
()
args
,
kwds
=
self
.
rhs
.
explicit_args_kwds
()
if
func_name
in
[
'declare'
,
'typedef'
]:
if
func_name
in
[
'declare'
,
'typedef'
]:
if
len
(
args
)
>
2
or
kwds
is
not
None
:
if
len
(
args
)
>
2
:
error
(
self
.
rhs
.
pos
,
"Can only declare one type at a time
."
)
error
(
args
[
2
].
pos
,
"Invalid positional argument
."
)
return
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
)
type
=
args
[
0
].
analyse_as_type
(
env
)
if
type
is
None
:
if
type
is
None
:
error
(
args
[
0
].
pos
,
"Unknown type"
)
error
(
args
[
0
].
pos
,
"Unknown type"
)
...
@@ -4853,7 +4859,7 @@ class SingleAssignmentNode(AssignmentNode):
...
@@ -4853,7 +4859,7 @@ class SingleAssignmentNode(AssignmentNode):
error
(
lhs
.
pos
,
"Invalid declaration"
)
error
(
lhs
.
pos
,
"Invalid declaration"
)
return
return
for
var
,
pos
in
vars
:
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
:
if
len
(
args
)
==
2
:
# we have a value
# we have a value
self
.
rhs
=
args
[
1
]
self
.
rhs
=
args
[
1
]
...
...
docs/src/tutorial/pure.rst
View file @
3822c930
...
@@ -176,6 +176,15 @@ Static typing
...
@@ -176,6 +176,15 @@ Static typing
self.a = 3
self.a = 3
self.b = b
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
* ``@cython.locals`` is a decorator that is used to specify the types of local
variables in the function body (including the arguments)::
variables in the function body (including the arguments)::
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment