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
79bb7559
Commit
79bb7559
authored
Jul 14, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up Pyrex comparison doc page
parent
c200ca4f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
21 deletions
+22
-21
docs/src/tutorial/pure.rst
docs/src/tutorial/pure.rst
+3
-0
docs/src/userguide/pyrex_differences.rst
docs/src/userguide/pyrex_differences.rst
+19
-21
No files found.
docs/src/tutorial/pure.rst
View file @
79bb7559
.. _pure-mode:
Pure Python Mode
================
...
...
docs/src/userguide/pyrex_differences.rst
View file @
79bb7559
...
...
@@ -43,7 +43,7 @@ generally preferred to use the usual :keyword:`for` ... :keyword:`in`
.. note:: see :ref:`automatic-range-conversion`
Note that Cython also supports set literals starting from Python 2.
3
.
Note that Cython also supports set literals starting from Python 2.
4
.
Keyword-only arguments
----------------------
...
...
@@ -68,8 +68,8 @@ takes exactly two positional parameters and has two required keyword parameters.
Conditional expressions "x if b else y"
(Python 2.5)
=========================================
============
Conditional expressions "x if b else y"
=========================================
Conditional expressions as described in
http://www.python.org/dev/peps/pep-0308/::
...
...
@@ -156,8 +156,8 @@ Cython. One can declare variables and return values for functions to be of the
cdef bint b = x
The first conversion would happen via ``x.__int__()`` whereas the second would
happen via ``x.__
nonzero__()``. (Actually, if ``x`` is the python object
``True`` or ``False`` then no method call is made.)
happen via ``x.__
bool__()`` (a.k.a. ``__nonzero__()``), with appropriate
optimisations for known builtin types.
Executable class bodies
=======================
...
...
@@ -181,18 +181,18 @@ essentially think of a :keyword:`cpdef` method as a :keyword:`cdef` method +
some extras. (That's how it's implemented at least.) First, it creates a
:keyword:`def` method that does nothing but call the underlying
:keyword:`cdef` method (and does argument unpacking/coercion if needed). At
the top of the :keyword:`cdef` method a little bit of code is added to
check
to see if it's overridden. Specifically, in
pseudocode::
the top of the :keyword:`cdef` method a little bit of code is added to
see
if it's overridden, similar to the following
pseudocode::
if
type(self) has a __dict__
:
foo = self.
getattr('foo')
if
hasattr(type(self), '__dict__')
:
foo = self.
foo
if foo is not wrapper_foo:
return foo(args)
[cdef method body]
To detect whether or not a type has a dictionary, it just checks the
tp_dictoffset slot, which is ``NULL`` (by default) for extension types, but
non- null for instance classes. If the dictionary exists, it does a single
``tp_dictoffset`` slot, which is ``NULL`` (by default) for extension types,
but
non- null for instance classes. If the dictionary exists, it does a single
attribute lookup and can tell (by comparing pointers) whether or not the
returned result is actually a new function. If, and only if, it is a new
function, then the arguments packed into a tuple and the method called. This
...
...
@@ -240,10 +240,10 @@ In Cython ``<type>x`` will try and do a coercion (as would happen on assignment
It does not stop one from casting where there is no conversion (though it will
emit a warning). If one really wants the address, cast to a ``void *`` first.
As in Pyrex ``<MyExtensionType>x`` will cast ``x`` to type :c:type:`MyExtensionType`
without any
type checking. Cython supports the syntax ``<MyExtensionType?>`` to do the cast
with type checking (i.e. it will throw an error if ``x`` is not a (subclass of)
:c:type:`MyExtensionType`.
As in Pyrex ``<MyExtensionType>x`` will cast ``x`` to type :c:type:`MyExtensionType`
without any type checking. Cython supports the syntax ``<MyExtensionType?>`` to do
the cast with type checking (i.e. it will throw an error if ``x`` is not a
(subclass of)
:c:type:`MyExtensionType`.
Optional arguments in cdef/cpdef functions
============================================
...
...
@@ -329,7 +329,8 @@ Cython emits a (non-spoofable and faster) typecheck whenever
From __future__ directives
==========================
Cython supports several from __future__ directives, namely ``unicode_literals`` and ``division``.
Cython supports several ``from __future__ import ...`` directives, namely
``absolute_import``, ``unicode_literals``, ``print_function`` and ``division``.
With statements are always enabled.
...
...
@@ -340,7 +341,4 @@ Cython has support for compiling ``.py`` files, and
accepting type annotations using decorators and other
valid Python syntax. This allows the same source to
be interpreted as straight Python, or compiled for
optimized results.
See http://wiki.cython.org/pure
for more details.
optimized results. See :ref:`pure-mode` for more details.
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