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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
0f6795d0
Commit
0f6795d0
authored
Jun 27, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gave a shrubbery to the knights.
parent
084a25f5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
11 deletions
+19
-11
docs/examples/userguide/extension_types/my_module.pxd
docs/examples/userguide/extension_types/my_module.pxd
+2
-0
docs/examples/userguide/extension_types/shrubbery_2.pyx
docs/examples/userguide/extension_types/shrubbery_2.pyx
+8
-0
docs/examples/userguide/extension_types/widen_shrubbery.pyx
docs/examples/userguide/extension_types/widen_shrubbery.pyx
+4
-0
docs/src/userguide/extension_types.rst
docs/src/userguide/extension_types.rst
+5
-11
No files found.
docs/examples/userguide/extension_types/my_module.pxd
0 → 100644
View file @
0f6795d0
cdef
class
Shrubbery
:
cdef
int
width
,
height
docs/examples/userguide/extension_types/shrubbery_2.pyx
0 → 100644
View file @
0f6795d0
from
my_module
cimport
Shrubbery
cdef
Shrubbery
another_shrubbery
(
Shrubbery
sh1
):
cdef
Shrubbery
sh2
sh2
=
Shrubbery
()
sh2
.
width
=
sh1
.
width
sh2
.
height
=
sh1
.
height
return
sh2
docs/examples/userguide/extension_types/widen_shrubbery.pyx
0 → 100644
View file @
0f6795d0
from
my_module
cimport
Shrubbery
cdef
widen_shrubbery
(
Shrubbery
sh
,
extra_width
):
sh
.
width
=
sh
.
width
+
extra_width
docs/src/userguide/extension_types.rst
View file @
0f6795d0
...
@@ -105,21 +105,15 @@ will be very inefficient. If the attribute is private, it will not work at all
...
@@ -105,21 +105,15 @@ will be very inefficient. If the attribute is private, it will not work at all
-- the code will compile, but an attribute error will be raised at run time.
-- the code will compile, but an attribute error will be raised at run time.
The solution is to declare ``sh`` as being of type :class:`Shrubbery`, as
The solution is to declare ``sh`` as being of type :class:`Shrubbery`, as
follows:
:
follows:
cdef widen_shrubbery(Shrubbery sh, extra_width):
.. literalinclude:: ../../examples/userguide/extension_types/widen_shrubbery.pyx
sh.width = sh.width + extra_width
Now the Cython compiler knows that ``sh`` has a C attribute called
Now the Cython compiler knows that ``sh`` has a C attribute called
:attr:`width` and will generate code to access it directly and efficiently.
:attr:`width` and will generate code to access it directly and efficiently.
The same consideration applies to local variables, for example,::
The same consideration applies to local variables, for example:
cdef Shrubbery another_shrubbery(Shrubbery sh1):
.. literalinclude:: ../../examples/userguide/extension_types/shrubbery_2.pyx
cdef Shrubbery sh2
sh2 = Shrubbery()
sh2.width = sh1.width
sh2.height = sh1.height
return sh2
Type Testing and Casting
Type Testing and Casting
...
...
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