Skip to content

Commit 1b6ad4a

Browse files
committed
Website build
1 parent c0b8fb8 commit 1b6ad4a

File tree

89 files changed

+16646
-916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+16646
-916
lines changed

10_trees_and_directed_acyclic_graphs.html

Lines changed: 1250 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<head>
66
<meta charset="utf-8" />
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8-
<title>9. Trees and directed acyclic graphs &#8212; Object oriented programming in Python for mathematicians 2020.0 documentation</title>
8+
<title>11. Further object-oriented features &#8212; Object oriented programming in Python for mathematicians 2020.0 documentation</title>
99
<link rel="stylesheet" href="_static/fenics.css" type="text/css" />
1010
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
1111
<link rel="stylesheet" type="text/css" href="_static/proof.css" />
@@ -19,8 +19,7 @@
1919
<script async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
2020
<link rel="index" title="Index" href="genindex.html" />
2121
<link rel="search" title="Search" href="search.html" />
22-
<link rel="next" title="10. Advanced Python scripting" href="42_advanced_python_scripting.html" />
23-
<link rel="prev" title="8. Debugging and testing" href="7_debugging.html" />
22+
<link rel="prev" title="10. Trees and directed acyclic graphs" href="10_trees_and_directed_acyclic_graphs.html" />
2423
<!--[if lte IE 6]>
2524
<link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
2625
<![endif]-->
@@ -37,7 +36,7 @@
3736
<div id="access">
3837
<div class="menu">
3938
<ul>
40-
<li class="page_item"><a href="https://github.com/finite-element/finite-element-course" title="GitHub">GitHub</a></li>
39+
<li class="page_item"><a href="https://github.com/object-oriented-python/object-oriented-programming" title="GitHub">GitHub</a></li>
4140
</ul>
4241
</div><!-- .menu -->
4342
</div><!-- #access -->
@@ -49,8 +48,17 @@
4948
<div class="bodywrapper">
5049
<div class="body" role="main">
5150

52-
<div class="section" id="trees-and-directed-acyclic-graphs">
53-
<h1><span class="section-number">9. </span>Trees and directed acyclic graphs<a class="headerlink" href="#trees-and-directed-acyclic-graphs" title="Permalink to this headline"></a></h1>
51+
<div class="section" id="further-object-oriented-features">
52+
<h1><span class="section-number">11. </span>Further object-oriented features<a class="headerlink" href="#further-object-oriented-features" title="Permalink to this headline"></a></h1>
53+
<div class="section" id="decorators">
54+
<h2><span class="section-number">11.1. </span>Decorators<a class="headerlink" href="#decorators" title="Permalink to this headline"></a></h2>
55+
</div>
56+
<div class="section" id="abstract-classes">
57+
<h2><span class="section-number">11.2. </span>Abstract classes<a class="headerlink" href="#abstract-classes" title="Permalink to this headline"></a></h2>
58+
</div>
59+
<div class="section" id="abstract-base-classes">
60+
<span id="id1"></span><h2><span class="section-number">11.3. </span>Abstract base classes<a class="headerlink" href="#abstract-base-classes" title="Permalink to this headline"></a></h2>
61+
</div>
5462
</div>
5563

5664

Lines changed: 69 additions & 39 deletions
Large diffs are not rendered by default.
Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
<script async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
2020
<link rel="index" title="Index" href="genindex.html" />
2121
<link rel="search" title="Search" href="search.html" />
22-
<link rel="next" title="3. Objects and abstraction" href="2_objects.html" />
23-
<link rel="prev" title="1. Introduction: abstraction in mathematics and programming" href="0_introduction.html" />
22+
<link rel="next" title="3. Objects and abstraction" href="3_objects.html" />
23+
<link rel="prev" title="1. Introduction: abstraction in mathematics and programming" href="1_introduction.html" />
2424
<!--[if lte IE 6]>
2525
<link rel="stylesheet" href="_static/ie6.css" type="text/css" media="screen" charset="utf-8" />
2626
<![endif]-->
@@ -37,7 +37,7 @@
3737
<div id="access">
3838
<div class="menu">
3939
<ul>
40-
<li class="page_item"><a href="https://github.com/finite-element/finite-element-course" title="GitHub">GitHub</a></li>
40+
<li class="page_item"><a href="https://github.com/object-oriented-python/object-oriented-programming" title="GitHub">GitHub</a></li>
4141
</ul>
4242
</div><!-- .menu -->
4343
</div><!-- #access -->
@@ -51,7 +51,7 @@
5151

5252
<div class="section" id="programs-in-files">
5353
<h1><span class="section-number">2. </span>Programs in files<a class="headerlink" href="#programs-in-files" title="Permalink to this headline"></a></h1>
54-
<p>This chapter is about how to combine pieces of code into larger units,
54+
<p>This week we will start to learn how to combine pieces of code into larger units,
5555
and how to package up your code so that you or others can do the same.
5656
You will previously have written Python code in Jupyter notebooks, and
5757
possibly used an interactive Python environment such as
@@ -86,7 +86,7 @@ <h2><span class="section-number">2.1. </span>The Python interpreter<a class="hea
8686
code works in essentially the same way no matter how you use
8787
Python. The Python interpreter also sits between the Python code and
8888
the operating system, so for most purposes, it also doesn’t matter
89-
whether your Python program is running on Windows, Mac, Linux, or
89+
whether your Python program is running on Windows, macOS, Linux, or
9090
maybe something more exotic. Usually, when we refer to Python doing
9191
something or responding to code in a particular way, what we mean is
9292
that this is what the interpreter does in those circumstances.</p>
@@ -105,10 +105,12 @@ <h2><span class="section-number">2.2. </span>Python scripts and text editors<a c
105105
Environment (IDE). IDEs combine an editor with a Python interpreter to
106106
run your code, a debugger and often other features such as integration
107107
with Git.</p>
108-
<div class="admonition note">
109-
<p class="admonition-title">Note</p>
110-
<p>Fill in more details once it becomes apparent which editors we’ll be using.</p>
111-
</div>
108+
<p>During this course, it will be assumed that you’re using the IDE Microsoft
109+
Visual Studio Code. You don’t have to do so, and if you have a strong preference
110+
for another text editor or IDE then you are welcome to use it. That said, if
111+
your text editor does not have a collaborative editing facility equivalent to
112+
Visual Studo Code’s Live Share, then you are likely to need to use Visual Studio
113+
Code when you ask for help so that the helper can share your editor session.</p>
112114
<div class="admonition note">
113115
<p class="admonition-title">Note</p>
114116
<p>Text files</p>
@@ -189,7 +191,7 @@ <h3><span class="section-number">2.2.2. </span>When to use scripts<a class="head
189191
scripts to a git repository, making a new commit every time you edit
190192
it, you would also be able to go back and find the point at which the
191193
script stopped working. We will return to this debugging technique in
192-
<a class="reference internal" href="7_debugging.html#bisection-debugging"><span class="std std-numref">Section 8.2.1</span></a>.</p>
194+
<a class="reference internal" href="9_debugging.html#bisection-debugging"><span class="std std-numref">Section 9.2.2</span></a>.</p>
193195
</div>
194196
<div class="section" id="when-not-to-use-scripts">
195197
<h3><span class="section-number">2.2.3. </span>When not to use scripts<a class="headerlink" href="#when-not-to-use-scripts" title="Permalink to this headline"></a></h3>
@@ -294,7 +296,7 @@ <h3><span class="section-number">2.3.2. </span>Other forms of import<a class="he
294296
are to be used frequently or in the middle of formulae: you probably
295297
don’t really want to write <a class="reference external" href="https://docs.python.org/3/library/math.html#math.sin" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">math.sin()</span></code></a> in every trig formula you
296298
ever write. One alternative is to rename the module on import. This is
297-
achieved using the keyword <code class="xref py py-obj docutils literal notranslate"><span class="pre">as</span></code> in an import statement. For example,
299+
achieved using the keyword <a class="reference external" href="https://docs.python.org/3/reference/simple_stmts.html#import" title="(in Python v3.9)"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">as</span></code></a> in an import statement. For example,
298300
it is usual to import the numerical Python module <a class="reference external" href="https://numpy.org/doc/stable/reference/index.html#module-numpy" title="(in NumPy v1.19)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy</span></code></a> in the
299301
following way:</p>
300302
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
@@ -567,12 +569,12 @@ <h2><span class="section-number">2.7. </span>Testing frameworks<a class="headerl
567569
<p>Attempting to establish whether a program correctly implements the
568570
intended algorithm is core to effective programming, and programmers
569571
often spend more time correcting bugs than writing new code. We will
570-
turn to the question of how to debug in <a class="reference internal" href="7_debugging.html#debugging"><span class="std std-numref">Section 8</span></a>. However,
572+
turn to the question of how to debug in <a class="reference internal" href="9_debugging.html#debugging"><span class="std std-numref">Section 9</span></a>. However,
571573
right from the start, we need to test the code we write, so we will cover
572574
the practical details of including tests in your code here.</p>
573575
<p>There are a number of Python packages which support code testing. The
574576
concepts are largely similar so rather than get bogged down in the
575-
details of multiple frameworks, we will introduce <a class="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v0.1.dev354+ga95da7a)"><span class="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
577+
details of multiple frameworks, we will introduce <a class="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.2.0.dev230+g775ba63c6)"><span class="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
576578
<div class="section" id="pytest-tests">
577579
<h3><span class="section-number">2.7.1. </span>Pytest tests<a class="headerlink" href="#pytest-tests" title="Permalink to this headline"></a></h3>
578580
<p>A Pytest test is simply a function whose name starts with <code class="xref py py-obj docutils literal notranslate"><span class="pre">test_</span></code>. In
@@ -664,7 +666,7 @@ <h3><span class="section-number">2.7.2. </span>Pytest files<a class="headerlink"
664666
</div>
665667
<p>Here we can see an <code class="xref py py-obj docutils literal notranslate"><span class="pre">F</span></code> after <code class="xref py py-obj docutils literal notranslate"><span class="pre">tests/test_fibonacci.py</span></code> indicating
666668
that the test failed, and we see some output detailing what went
667-
wrong. We will learn how to interpret this output in <a class="reference internal" href="7_debugging.html#debugging"><span class="std std-numref">Section 8</span></a>.</p>
669+
wrong. We will learn how to interpret this output in <a class="reference internal" href="9_debugging.html#debugging"><span class="std std-numref">Section 9</span></a>.</p>
668670
</div>
669671
<div class="section" id="additional-useful-pytest-tricks">
670672
<h3><span class="section-number">2.7.3. </span>Additional useful pytest tricks<a class="headerlink" href="#additional-useful-pytest-tricks" title="Permalink to this headline"></a></h3>
@@ -682,13 +684,22 @@ <h3><span class="section-number">2.7.3. </span>Additional useful pytest tricks<a
682684
series of tests to fail, resulting in a very long list of error messages which
683685
is hard to read. A useful tool in this circumstance is the <code class="xref py py-obj docutils literal notranslate"><span class="pre">-x</span></code> option, which
684686
tells pytest to stop after the first test fail. For example:</p>
685-
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> py.test -x <span class="nb">test</span>
687+
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> py.test -x tests
686688
</pre></div>
687689
</div>
688690
<p>The tests are usually arranged in increasing order of sophistication, so the
689691
earlier tests are likely to catch the most basic errors in your code. For this
690692
reason, it is usually the best policy to try to fix the first error first, and
691693
only move onto the next problem when the previous test passes.</p>
694+
<div class="admonition note">
695+
<p class="admonition-title">Note</p>
696+
<p>The exercise repositories in this course will usually contain a
697+
<code class="file docutils literal notranslate"><span class="pre">tests</span></code> directory full of tests that check that you have correctly
698+
implemented the week’s exercises. You should get in the habit of running the
699+
tests as you work through the exercises, as they are designed not just to
700+
pass if your code is correct, but to provide feedback as to what might be
701+
going wrong if your code contains errors.</p>
702+
</div>
692703
</div>
693704
</div>
694705
<div class="section" id="writing-code-to-a-specified-interface">
@@ -767,24 +778,35 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
767778
installation page</span></a> to create the folder structure
768779
you will use for this course on your computer. Start with an overall folder
769780
for the module, and create a virtual environment in that module.</p>
781+
</div></div><div class="proof proof-type-exercise" id="id6">
782+
783+
<div class="proof-title">
784+
<span class="proof-type">Exercise 2.2</span>
785+
786+
</div><div class="proof-content">
787+
<p>Visit the <a class="reference external" href="https://github.com/object-oriented-python/object-oriented-programming">GitHub repository for these notes</a>.
788+
Clone that git repository into your course folder, and install the Python
789+
package it contains into your virtual environment. Check that it has
790+
installed correctly by running IPython, importing <a class="reference internal" href="fibonacci.html#module-fibonacci" title="fibonacci"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fibonacci</span></code></a> and
791+
trying out <a class="reference internal" href="fibonacci.html#fibonacci.fibonacci.fib" title="fibonacci.fibonacci.fib"><code class="xref py py-func docutils literal notranslate"><span class="pre">fibonacci.fib</span></code></a>.</p>
770792
</div></div><div class="admonition note">
771793
<p class="admonition-title">Note</p>
772794
<p>The first GitHub classroom assignment for this module will be released at
773795
the start of term.</p>
774796
</div>
775-
<div class="proof proof-type-exercise" id="id6">
797+
<div class="proof proof-type-exercise" id="id7">
776798

777799
<div class="proof-title">
778-
<span class="proof-type">Exercise 2.2</span>
800+
<span class="proof-type">Exercise 2.3</span>
779801

780802
</div><div class="proof-content">
781803
<p>Accept the <a class="reference internal" href="not_released.html"><span class="doc">first Github Classroom assignment for this module</span></a> and clone it into your course folder. The assignment
782804
repository just contains a <code class="file docutils literal notranslate"><span class="pre">README</span></code> and some tests. Your job in the
783805
following exercises will be to populate it with the remaining content.</p>
784-
</div></div><div class="proof proof-type-exercise" id="id7">
806+
</div></div><div class="proof proof-type-exercise" id="id8">
785807

786808
<div class="proof-title">
787-
<span class="proof-type">Exercise 2.3</span>
809+
<span class="proof-type">Exercise 2.4</span>
788810

789811
</div><div class="proof-content">
790812
<p>Create a new Python <a class="reference internal" href="#term-package"><span class="xref std std-term">package</span></a> named <code class="xref py py-mod docutils literal notranslate"><span class="pre">math_utils</span></code> containing a
@@ -802,19 +824,27 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
802824
</pre></div>
803825
</div>
804826
</div>
805-
</div></div><div class="proof proof-type-exercise" id="id8">
827+
<div class="admonition note">
828+
<p class="admonition-title">Note</p>
829+
<p>After this and every exercise in which you write code, ensure that you
830+
add any new files to git, commit all of your changes, and push to
831+
GitHub. Then ensure that the tests pass on GitHub. For more information
832+
about how to do any of these, refer back the <a class="reference external" href="https://imperial-fons-computing.github.io/git.html#github-classroom-exercise" title="(in Installation instructions for FoNS v2020.0)"><span class="xref std std-ref">Faculty of Natural Sciences
833+
Git instructions</span></a>.</p>
834+
</div>
835+
</div></div><div class="proof proof-type-exercise" id="id9">
806836

807837
<div class="proof-title">
808-
<span class="proof-type">Exercise 2.4</span>
838+
<span class="proof-type">Exercise 2.5</span>
809839

810840
</div><div class="proof-content">
811841
<p>Following <a class="reference internal" href="#installable-packages"><span class="std std-numref">Section 2.4.2</span></a>, create a <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> file in
812842
your exercise repository, so that the <code class="xref py py-mod docutils literal notranslate"><span class="pre">math_utils</span></code> <a class="reference internal" href="#term-package"><span class="xref std std-term">package</span></a> is
813843
installable.</p>
814-
</div></div><div class="proof proof-type-exercise" id="id9">
844+
</div></div><div class="proof proof-type-exercise" id="id10">
815845

816846
<div class="proof-title">
817-
<span class="proof-type">Exercise 2.5</span>
847+
<span class="proof-type">Exercise 2.6</span>
818848

819849
</div><div class="proof-content">
820850
<p>Add an <a class="reference external" href="https://docs.python.org/3/reference/simple_stmts.html#import" title="(in Python v3.9)"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">import</span></code></a> to <code class="file docutils literal notranslate"><span class="pre">math_utils.__init__.py</span></code> so that the following

0 commit comments

Comments
 (0)