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
bd25194d
Commit
bd25194d
authored
Jul 06, 2018
by
scoder
Committed by
GitHub
Jul 06, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2414 from gabrieldemarmiesse/test_language_basics_4
Added tests for "language basics" part 4
parents
15205ce9
2c739e07
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
55 deletions
+31
-55
docs/examples/userguide/language_basics/optional_subclassing.pxd
...amples/userguide/language_basics/optional_subclassing.pxd
+8
-0
docs/examples/userguide/language_basics/optional_subclassing.pyx
...amples/userguide/language_basics/optional_subclassing.pyx
+13
-0
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+6
-38
docs/src/userguide/pyrex_differences.rst
docs/src/userguide/pyrex_differences.rst
+4
-17
No files found.
docs/examples/userguide/language_basics/optional_subclassing.pxd
0 → 100644
View file @
bd25194d
cdef
class
A
:
cdef
foo
(
self
)
cdef
class
B
(
A
):
cdef
foo
(
self
,
x
=*
)
cdef
class
C
(
B
):
cpdef
foo
(
self
,
x
=*
,
int
k
=*
)
docs/examples/userguide/language_basics/optional_subclassing.pyx
0 → 100644
View file @
bd25194d
from
__future__
import
print_function
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
)
docs/src/userguide/language_basics.rst
View file @
bd25194d
...
@@ -300,35 +300,15 @@ To avoid repetition (and potential future inconsistencies), default argument val
...
@@ -300,35 +300,15 @@ To avoid repetition (and potential future inconsistencies), default argument val
not visible in the declaration (in ``.pxd`` files) but only in
not visible in the declaration (in ``.pxd`` files) but only in
the implementation (in ``.pyx`` files).
the implementation (in ``.pyx`` files).
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:
from __future__ import print_function
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)
.. literalinclude:: ../../examples/userguide/language_basics/optional_subclassing.pyx
When in a ``.pxd`` file, the signature is different like this example: ``cdef foo(x=*)``.
When in a ``.pxd`` file, the signature is different like this example: ``cdef foo(x=*)``.
This is because the program calling the function just needs to know what signatures are
This is because the program calling the function just needs to know what signatures are
possible in C, but doesn't need to know the value of the default arguments.::
possible in C, but doesn't need to know the value of the default arguments.:
cdef class A:
cdef foo(self)
cdef class B(A):
cdef foo(self, x=*)
cdef class C(B):
cpdef foo(self, x=*, int k=*)
.. literalinclude:: ../../examples/userguide/language_basics/optional_subclassing.pxd
.. note::
.. note::
The number of arguments may increase when subclassing,
The number of arguments may increase when subclassing,
...
@@ -481,21 +461,9 @@ Overriding in extension types
...
@@ -481,21 +461,9 @@ Overriding in extension types
-----------------------------
-----------------------------
``cpdef`` methods can override ``cdef`` methods::
``cpdef`` methods can override ``cdef`` methods:
from __future__ import print_function
cdef class A:
cdef foo(self):
print("A")
cdef class B(A):
cdef foo(self, x=None):
print("B", x)
cdef class C(B):
.. literalinclude:: ../../examples/userguide/language_basics/optional_subclassing.pyx
cpdef foo(self, x=True, int k=3):
print("C", x, k)
When subclassing an extension type with a Python class,
When subclassing an extension type with a Python class,
``def`` methods can override ``cpdef`` methods but not ``cdef``
``def`` methods can override ``cpdef`` methods but not ``cdef``
...
...
docs/src/userguide/pyrex_differences.rst
View file @
bd25194d
...
@@ -261,26 +261,13 @@ remain the same. There is a slight performance penalty in some cases when a
...
@@ -261,26 +261,13 @@ remain the same. There is a slight performance penalty in some cases when a
cdef/cpdef function without any optional is overridden with one that does have
cdef/cpdef function without any optional is overridden with one that does have
default argument values.
default argument values.
For example, one can have the ``.pxd`` file:
:
For example, one can have the ``.pxd`` file:
cdef class A:
.. literalinclude:: ../../examples/userguide/language_basics/optional_subclassing.pxd
cdef foo(self)
cdef class B(A)
cdef foo(self, x=*)
cdef class C(B):
cpdef foo(self, x=*, int k=*)
with corresponding ``.pyx`` file:
:
with corresponding ``.pyx`` file:
cdef class A:
.. literalinclude:: ../../examples/userguide/language_basics/optional_subclassing.pyx
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
.. note::
.. note::
...
...
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