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
40eff9ef
Commit
40eff9ef
authored
8 years ago
by
Robert Bradshaw
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #523 from jdemeyer/cpdef_doc
Improve documentation for cpdef methods
parents
8a50c581
174de4af
No related merge requests found
Changes
1
Hide 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 @
40eff9ef
...
@@ -153,7 +153,7 @@ the same effect as the C directive ``#pragma pack(1)``.
...
@@ -153,7 +153,7 @@ the same effect as the C directive ``#pragma pack(1)``.
cheddar, edam,
cheddar, edam,
camembert
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:
cpdef enum CheeseState:
hard = 1
hard = 1
...
@@ -267,7 +267,7 @@ Optional Arguments
...
@@ -267,7 +267,7 @@ Optional Arguments
------------------
------------------
* Are supported for ``cdef`` and ``cpdef`` functions
* 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::
* When in a ``.pyx`` file, the signature is the same as it is in Python itself::
...
@@ -538,8 +538,8 @@ Functions and Methods
...
@@ -538,8 +538,8 @@ Functions and Methods
* Only "Python" functions can be called outside a Cython module from *Python interpreted code*.
* 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 declared with the ``def`` statement
* Are called with Python objects
* Are called with Python objects
...
@@ -548,8 +548,8 @@ Callable from Python
...
@@ -548,8 +548,8 @@ Callable from Python
.. _cdef:
.. _cdef:
Callable from C
Callable from C
(cdef)
================
================
======
* Are declared with the ``cdef`` statement.
* Are declared with the ``cdef`` statement.
* Are called with either Python objects or C values.
* Are called with either Python objects or C values.
...
@@ -557,8 +557,8 @@ Callable from C
...
@@ -557,8 +557,8 @@ Callable from C
.. _cpdef:
.. _cpdef:
Callable from both Python and C
Callable from both Python and C
(cpdef)
================================
================================
=======
* Are declared with the ``cpdef`` statement.
* Are declared with the ``cpdef`` statement.
* Can be called from anywhere, because it uses a little Cython magic.
* Can be called from anywhere, because it uses a little Cython magic.
...
@@ -567,18 +567,40 @@ Callable from both Python and C
...
@@ -567,18 +567,40 @@ Callable from both Python and C
Overriding
Overriding
==========
==========
``cpdef``
functions can override ``cdef`` function
s::
``cpdef``
methods can override ``cdef`` method
s::
cdef class A:
cdef class A:
cdef foo(self):
cdef foo(self):
print "A"
print "A"
cdef class B(A)
cdef class B(A)
cdef foo(self, x=None)
cdef foo(self, x=None)
print "B", x
print "B", x
cdef class C(B):
cdef class C(B):
cpdef foo(self, x=True, int k=3)
cpdef foo(self, x=True, int k=3)
print "C", x, k
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
Function Pointers
=================
=================
...
...
This diff is collapsed.
Click to expand it.
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