Commit 4420cb6e authored by Robert Bradshaw's avatar Robert Bradshaw

Note on type inference and loop targets.

parent 8b4b796d
...@@ -137,8 +137,9 @@ in general, a ``nogil`` block may contain only "white" code. ...@@ -137,8 +137,9 @@ in general, a ``nogil`` block may contain only "white" code.
.. figure:: htmlreport.png .. figure:: htmlreport.png
Note that Cython deduces the type of local variables based on their assignments, Note that Cython deduces the type of local variables based on their assignments
which can also cut down on the need to explicitly specify types everywhere. (including as loop variable targets) which can also cut down on the need to
explicitly specify types everywhere.
For example, declaring ``dx`` to be of type double above is unnecessary, For example, declaring ``dx`` to be of type double above is unnecessary,
as is declaring the type of ``s`` in the last version (where the return type as is declaring the type of ``s`` in the last version (where the return type
of ``f`` is known to be a C double.) A notable exception, however, is of ``f`` is known to be a C double.) A notable exception, however, is
......
...@@ -397,6 +397,9 @@ Cython code. Here is the list of currently supported directives: ...@@ -397,6 +397,9 @@ Cython code. Here is the list of currently supported directives:
Infer types of untyped variables in function bodies. Default is Infer types of untyped variables in function bodies. Default is
None, indicating that only safe (semantically-unchanging) inferences None, indicating that only safe (semantically-unchanging) inferences
are allowed. are allowed.
In particular, inferring *integral* types for variables *used in arithmetic
expressions* is considered unsafe (due to possible overflow) and must be
explicitly requested.
``language_level`` (2/3) ``language_level`` (2/3)
Globally set the Python language level to be used for module Globally set the Python language level to be used for module
......
...@@ -510,6 +510,9 @@ comprehensions). For example, one can write:: ...@@ -510,6 +510,9 @@ comprehensions). For example, one can write::
f(value) f(value)
return [x*x for x in v if x % 2 == 0] return [x*x for x in v if x % 2 == 0]
If the loop target variable is unspecified, an assignment from type
``*container.begin()`` is used for :ref:`type inference <compiler-directives>`.
Simplified wrapping with default constructor Simplified wrapping with default constructor
-------------------------------------------- --------------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment