summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2018-06-20 07:01:52 +0200
committerStefan Behnel <stefan_ml@behnel.de>2018-06-20 07:01:52 +0200
commitc9f7bce24cd5ea92d0c898a8978afde8fa412a77 (patch)
treee447e1ceb6ecd6d4b05af310e26e81cf426ef89c /docs/examples/tutorial/string
parent3b04d75a9229a72400ce5e87e7f4e84a07131175 (diff)
downloadcython-c9f7bce24cd5ea92d0c898a8978afde8fa412a77.tar.gz
docs: Give the string input conversion function in the string tutorial a better name and clarify some comments.
Diffstat (limited to 'docs/examples/tutorial/string')
-rw-r--r--docs/examples/tutorial/string/api_func.pyx4
-rw-r--r--docs/examples/tutorial/string/to_unicode.pxd2
-rw-r--r--docs/examples/tutorial/string/to_unicode.pyx13
3 files changed, 10 insertions, 9 deletions
diff --git a/docs/examples/tutorial/string/api_func.pyx b/docs/examples/tutorial/string/api_func.pyx
index 99a20b618..ec6b27751 100644
--- a/docs/examples/tutorial/string/api_func.pyx
+++ b/docs/examples/tutorial/string/api_func.pyx
@@ -1,5 +1,5 @@
-from to_unicode cimport _ustring
+from to_unicode cimport _text
def api_func(s):
- text = _ustring(s)
+ text_input = _text(s)
# ...
diff --git a/docs/examples/tutorial/string/to_unicode.pxd b/docs/examples/tutorial/string/to_unicode.pxd
index cfb4a6080..43a7f73bb 100644
--- a/docs/examples/tutorial/string/to_unicode.pxd
+++ b/docs/examples/tutorial/string/to_unicode.pxd
@@ -1 +1 @@
-cdef unicode _ustring(s)
+cdef unicode _text(s)
diff --git a/docs/examples/tutorial/string/to_unicode.pyx b/docs/examples/tutorial/string/to_unicode.pyx
index 5b61ff220..8ab8f2662 100644
--- a/docs/examples/tutorial/string/to_unicode.pyx
+++ b/docs/examples/tutorial/string/to_unicode.pyx
@@ -2,19 +2,20 @@
from cpython.version cimport PY_MAJOR_VERSION
-cdef unicode _ustring(s):
+cdef unicode _text(s):
if type(s) is unicode:
- # fast path for most common case(s)
+ # Fast path for most common case(s).
return <unicode>s
elif PY_MAJOR_VERSION < 3 and isinstance(s, bytes):
- # only accept byte strings in Python 2.x, not in Py3
+ # Only accept byte strings as text input in Python 2.x, not in Py3.
return (<bytes>s).decode('ascii')
elif isinstance(s, unicode):
- # an evil cast to <unicode> might work here in some(!) cases,
- # depending on what the further processing does. to be safe,
- # we can always create a copy instead
+ # We know from the fast path above that 's' can only be a subtype here.
+ # An evil cast to <unicode> might still work in some(!) cases,
+ # depending on what the further processing does. To be safe,
+ # we can always create a copy instead.
return unicode(s)
else: