From 0333761571d245a9dd6dd37a196db4d3bf19afa4 Mon Sep 17 00:00:00 2001 From: gabrieldemarmiesse Date: Sun, 17 Jun 2018 11:30:02 +0200 Subject: [PATCH] Moved the first code snippet of the extension_types.rst to the examples directory for testing. --- .../userguide/extension_types/shrubbery.pyx | 12 ++++++++++++ docs/src/userguide/extension_types.rst | 16 ++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 docs/examples/userguide/extension_types/shrubbery.pyx diff --git a/docs/examples/userguide/extension_types/shrubbery.pyx b/docs/examples/userguide/extension_types/shrubbery.pyx new file mode 100644 index 00000000000..9d2a5481a0a --- /dev/null +++ b/docs/examples/userguide/extension_types/shrubbery.pyx @@ -0,0 +1,12 @@ +from __future__ import print_function + +cdef class Shrubbery: + cdef int width, height + + def __init__(self, w, h): + self.width = w + self.height = h + + def describe(self): + print("This shrubbery is", self.width, + "by", self.height, "cubits.") diff --git a/docs/src/userguide/extension_types.rst b/docs/src/userguide/extension_types.rst index 497ff91249f..5bc988e0544 100644 --- a/docs/src/userguide/extension_types.rst +++ b/docs/src/userguide/extension_types.rst @@ -12,21 +12,9 @@ Introduction As well as creating normal user-defined classes with the Python class statement, Cython also lets you create new built-in Python types, known as extension types. You define an extension type using the :keyword:`cdef` class -statement. Here's an example:: +statement. Here's an example: - from __future__ import print_function - - cdef class Shrubbery: - - cdef int width, height - - def __init__(self, w, h): - self.width = w - self.height = h - - def describe(self): - print("This shrubbery is", self.width, - "by", self.height, "cubits.") +.. literalinclude:: ../../examples/userguide/extension_types/shrubbery.pyx As you can see, a Cython extension type definition looks a lot like a Python class definition. Within it, you use the def statement to define methods that