From: Robert Bradshaw Date: Sun, 25 Jan 2009 10:18:29 +0000 (-0800) Subject: early binding X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1e5037d05686f6b6049b3d112b0bd75fcb89a9b5;p=cython.git early binding --- diff --git a/docs/language_basics.rst b/docs/language_basics.rst index d641bc0f..3cbbcc04 100644 --- a/docs/language_basics.rst +++ b/docs/language_basics.rst @@ -113,6 +113,9 @@ Python function will result in a compile-time error. C functions, on the other hand, can have parameters of any type, since they're passed in directly using a normal C function call. +A more complete comparison of the pros and cons of these different method +types can be found at :ref:`early-binding-for-speed`. + Python objects as parameters and return values ---------------------------------------------- @@ -492,27 +495,6 @@ the level of the include statement that is including the file. separate parts that may be more appropriate in many cases. See :ref:`sharing-declarations`. -Keyword-only arguments -====================== - -Python functions can have keyword-only arguments listed after the ``*`` -parameter and before the ``**`` parameter if any, e.g.:: - - def f(a, b, *args, c, d = 42, e, **kwds): - ... - -Here ``c``, ``d`` and ``e`` cannot be passed as position arguments and must be -passed as keyword arguments. Furthermore, ``c`` and ``e`` are required keyword -arguments, since they do not have a default value. - -If the parameter name after the ``*`` is omitted, the function will not accept any -extra positional arguments, e.g.:: - - def g(a, b, *, c, d): - ... - -takes exactly two positional parameters and has two required keyword parameters. - Conditional Compilation ======================= diff --git a/docs/limitations.rst b/docs/limitations.rst index bd537f19..66961594 100644 --- a/docs/limitations.rst +++ b/docs/limitations.rst @@ -54,23 +54,6 @@ Using the yield keywords. (work in progress) This relies on functional closures .. This needs to be well thought-out, and I think Pyrex has some plans along .. these lines as well. -Modulo '%' operation on floats -------------------------------- -:: - - a = b%c - -where `b` and `c` are floats will raise the error "Invalid operand types for '%' (float; float)" - -This can currently be worked around by putting:: - - cdef extern from "math.h": - double fmod(double x, double y) - -somewhere is the source file and then using:: - - a = fmod(b,c) - Other Current Limitations ========================== diff --git a/docs/pyrex_differences.rst b/docs/pyrex_differences.rst index e863d91b..bf7cd03d 100644 --- a/docs/pyrex_differences.rst +++ b/docs/pyrex_differences.rst @@ -6,8 +6,28 @@ Differences between Cython and Pyrex ************************************** +.. warning:: + Both Cython and Pyrex are moving targets. It has come to the point + that an explicit list of all the differences between the two + projects would be laborious to list and track, but hopefully + this high-level list gives an idea of the differences that + are present. It should be noted that both projects make an effort + at mutual compatibility, but Cython's goal is to be as close to + and complete as Python as reasonable. + + +Python 3.0 Support +================== + +Cython creates ``.c`` files that can be built and used with both +Python 2.x and Python 3.x. In fact, compiling your module with +Cython may very well be the easiest way to port code to Python 3.0. +We are also working to make the compiler run in both Python 2.x and 3.0. + +Many Python 3 constructs are already supported by Cython. + List/Set/Dict Comprehensions -============================= +---------------------------- Cython supports the different comprehensions defined by Python 3.0 for lists, sets and dicts:: @@ -25,6 +45,28 @@ generally preferred to use the usual :keyword:`for` ... :keyword:`in` Note that Cython also supports set literals starting from Python 2.3. +Keyword-only arguments +---------------------- + +Python functions can have keyword-only arguments listed after the ``*`` +parameter and before the ``**`` parameter if any, e.g.:: + + def f(a, b, *args, c, d = 42, e, **kwds): + ... + +Here ``c``, ``d`` and ``e`` cannot be passed as position arguments and must be +passed as keyword arguments. Furthermore, ``c`` and ``e`` are required keyword +arguments, since they do not have a default value. + +If the parameter name after the ``*`` is omitted, the function will not accept any +extra positional arguments, e.g.:: + + def g(a, b, *, c, d): + ... + +takes exactly two positional parameters and has two required keyword parameters. + + Conditional expressions "x if b else y" (python 2.5) ===================================================== @@ -114,7 +156,7 @@ happen via ``x.__nonzero__()``. (Actually, if ``x`` is the python object ``True`` or ``False`` then no method call is made.) Executable class bodies -========================= +======================= Including a working :func:`classmethod`:: @@ -280,3 +322,21 @@ Rather than introducing a new keyword :keyword:`typecheck` as explained in the Cython emits a (non-spoofable and faster) typecheck whenever :func:`isinstance` is used with an extension type as the second parameter. +From __future__ directives +========================== + +Cython supports several from __future__ directives, namely ``unicode_literals`` and ``division``. + +With statements are always enabled. + +Pure Python mode +================ + +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. +