Commit 016762d1 authored by mitch's avatar mitch Committed by Stefan Behnel

updated documentation to mention 'const' for read-only buffers

parent f875f4c2
...@@ -220,14 +220,15 @@ object. This can simply be done as follows: ...@@ -220,14 +220,15 @@ object. This can simply be done as follows:
.. literalinclude:: ../../examples/tutorial/string/return_memview.pyx .. literalinclude:: ../../examples/tutorial/string/return_memview.pyx
If the byte input is actually encoded text, and the further processing For read-only buffers, like :obj:`bytes`, the memoryview item type should
should happen at the Unicode level, then the right thing to do is to be declared as ``const`` (see :ref:`readonly_views`). If the byte input is
decode the input straight away. This is almost only a problem in Python actually encoded text, and the further processing should happen at the
2.x, where Python code expects that it can pass a byte string (:obj:`str`) Unicode level, then the right thing to do is to decode the input straight
with encoded text into a text API. Since this usually happens in more away. This is almost only a problem in Python 2.x, where Python code
than one place in the module's API, a helper function is almost always the expects that it can pass a byte string (:obj:`str`) with encoded text into
way to go, since it allows for easy adaptation of the input normalisation a text API. Since this usually happens in more than one place in the
process later. module's API, a helper function is almost always the way to go, since it
allows for easy adaptation of the input normalisation process later.
This kind of input normalisation function will commonly look similar to This kind of input normalisation function will commonly look similar to
the following: the following:
......
...@@ -153,6 +153,9 @@ As for NumPy, new axes can be introduced by indexing an array with ``None`` :: ...@@ -153,6 +153,9 @@ As for NumPy, new axes can be introduced by indexing an array with ``None`` ::
One may mix new axis indexing with all other forms of indexing and slicing. One may mix new axis indexing with all other forms of indexing and slicing.
See also an example_. See also an example_.
.. _readonly_views:
Read-only views Read-only views
--------------- ---------------
......
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