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
02c5228b
Commit
02c5228b
authored
Jun 21, 2016
by
Jeroen Demeyer
Committed by
Stefan Behnel
Jul 15, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve documentation for cpdef methods
parent
b5846e0c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
9 deletions
+31
-9
docs/src/reference/language_basics.rst
docs/src/reference/language_basics.rst
+31
-9
No files found.
docs/src/reference/language_basics.rst
View file @
02c5228b
...
...
@@ -153,7 +153,7 @@ the same effect as the C directive ``#pragma pack(1)``.
cheddar, edam,
camembert
Declaring an enum as ``
`cpdef`` will create a PEP 435
-style Python wrapper::
Declaring an enum as ``
cpdef`` will create a :pep:`435`
-style Python wrapper::
cpdef enum CheeseState:
hard = 1
...
...
@@ -267,7 +267,7 @@ Optional Arguments
------------------
* Are supported for ``cdef`` and ``cpdef`` functions
* There
differences though whether you declare them in a ``.pyx`` file or a ``.pxd`` file
* There
are differences though whether you declare them in a ``.pyx`` file or a ``.pxd`` file:
* When in a ``.pyx`` file, the signature is the same as it is in Python itself::
...
...
@@ -538,8 +538,8 @@ Functions and Methods
* Only "Python" functions can be called outside a Cython module from *Python interpreted code*.
Callable from Python
=====================
Callable from Python
(def)
=====================
=====
* Are declared with the ``def`` statement
* Are called with Python objects
...
...
@@ -548,8 +548,8 @@ Callable from Python
.. _cdef:
Callable from C
================
Callable from C
(cdef)
================
======
* Are declared with the ``cdef`` statement.
* Are called with either Python objects or C values.
...
...
@@ -557,8 +557,8 @@ Callable from C
.. _cpdef:
Callable from both Python and C
================================
Callable from both Python and C
(cpdef)
================================
=======
* Are declared with the ``cpdef`` statement.
* Can be called from anywhere, because it uses a little Cython magic.
...
...
@@ -567,18 +567,40 @@ Callable from both Python and C
Overriding
==========
``cpdef``
functions can override ``cdef`` function
s::
``cpdef``
methods can override ``cdef`` method
s::
cdef class A:
cdef foo(self):
print "A"
cdef class B(A)
cdef foo(self, x=None)
print "B", x
cdef class C(B):
cpdef foo(self, x=True, int k=3)
print "C", x, k
When subclassing an extension type with a Python class,
``def`` methods can override ``cpdef`` methods but not ``cdef``
methods::
cdef class A:
cdef foo(self):
print("A")
cdef class B(A):
cpdef foo(self):
print("B")
class C(B): # NOTE: not cdef class
def foo(self):
print("C")
If ``C`` above would be an extension type (``cdef class``),
this would not work correctly.
The Cython compiler will give a warning in that case.
Function Pointers
=================
...
...
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