You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p><aclass="reference internal" href="#tree-evaluate"><spanclass="std std-numref">Listing 10.6</span></a> shows a single dispatch function for a visitor function
813
812
which evaluates a <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Expression</span></code>. Start with lines 6-19. These define a
814
-
function <aclass="reference internal" href="example_code.html#example_code.expression_tools.evaluate" title="example_code.expression_tools.evaluate"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">evaluate()</span></code></a> which will be used in
813
+
function <codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">evaluate()</span></code> which will be used in
815
814
the default case, that is, in the case where the <aclass="reference external" href="https://docs.python.org/3/library/functions.html#type" title="(in Python v3.9)"><codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">type</span></code></a> of the first
816
815
argument doesn’t match any of the other implementations of
817
-
<aclass="reference internal" href="example_code.html#example_code.expression_tools.evaluate" title="example_code.expression_tools.evaluate"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">evaluate()</span></code></a>. In this case, the first
816
+
<codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">evaluate()</span></code>. In this case, the first
818
817
argument is the expression that we’re evaluating, so if the type doesn’t match
819
818
then this means that we don’t know how to evaluate this object, and the only
820
819
course of action available is to throw an <aclass="reference internal" href="6_exceptions.html#term-exception"><spanclass="xref std std-term">exception</span></a>.</p>
Notice that the function name is given as <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">_</span></code>. This is the Python convention for
833
832
a name which will never be used. This function will never be called by its
834
833
declared name. Instead, look at the decorator on line 26. The single dispatch
835
-
function <aclass="reference internal" href="example_code.html#example_code.expression_tools.evaluate" title="example_code.expression_tools.evaluate"><codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">evaluate()</span></code></a> has a <aclass="reference internal" href="3_objects.html#term-method"><spanclass="xref std std-term">method</span></a>
834
+
function <codeclass="xref py py-func docutils literal notranslate"><spanclass="pre">evaluate()</span></code> has a <aclass="reference internal" href="3_objects.html#term-method"><spanclass="xref std std-term">method</span></a>
836
835
<codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">register()</span></code>. When used as a decorator, the <codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">register()</span></code> method of a
837
836
single dispatch function registers the function that follows as implementation
838
837
for the <aclass="reference external" href="https://docs.python.org/3/reference/compound_stmts.html#class" title="(in Python v3.9)"><codeclass="xref std std-keyword docutils literal notranslate"><spanclass="pre">class</span></code></a> given as an argument to <codeclass="xref py py-meth docutils literal notranslate"><spanclass="pre">register()</span></code>. On this
839
838
occasion, this is <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">expressions.Number</span></code>.</p>
840
839
<p>Now look at lines 31-33. These contain the implementation of
<h4><spanclass="section-number">1.3.8.4. </span>Including links<aclass="headerlink" href="#including-links" title="Permalink to this headline">¶</a></h4>
535
534
<p>Just dumping URLs into the text often results in hard to read code. Instead,
536
535
Markdown enables you to write the link text in square brackets followed by the
537
-
URL in round brackets. So <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">[the</span><spanclass="pre">Markdown</span><spanclass="pre">Cheat</span>
<h4><spanclass="section-number">1.3.8.5. </span>More advanced Markdown<aclass="headerlink" href="#more-advanced-markdown" title="Permalink to this headline">¶</a></h4>
containing a file <codeclass="file docutils literal notranslate"><spanclass="pre">__init__.py</span></code>. It can also contain modules and
508
503
further subpackages.</p>
509
504
</dd>
510
-
<dt><codeclass="file docutils literal notranslate"><spanclass="pre">setup.py</span></code></dt><dd><p>This file is outside the package directory and is not
505
+
<dt><codeclass="file docutils literal notranslate"><spanclass="pre">setup.py</span></code></dt><dd><p>This file is outside the package folder and is not
511
506
actually a part of the package. The role of <codeclass="file docutils literal notranslate"><spanclass="pre">setup.py</span></code> will be
512
507
covered in <aclass="reference internal" href="#installable-packages"><spanclass="std std-numref">Section 2.6.2</span></a>.</p>
513
508
</dd>
@@ -602,7 +597,7 @@ <h3><span class="section-number">2.6.3. </span>Installing a package from local c
602
597
repository: the folder containing <codeclass="file docutils literal notranslate"><spanclass="pre">setup.py</span></code>. The option flag <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">-e</span></code>
603
598
tells pip to install the package in ‘editable’ mode. This means that
604
599
instead of copying the package files to your venv’s Python packages
605
-
directory, symbolic links will be created. This means that any changes
600
+
folder, symbolic links will be created. This means that any changes
606
601
that you make to your package will show up the next time the package
607
602
is imported in a new Python process, avoiding the need to reinstall
the practical details of including tests in your code here.</p>
643
638
<p>There are a number of Python packages which support code testing. The
644
639
concepts are largely similar so rather than get bogged down in the
645
-
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.3.0.dev67+g7585221d5)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
640
+
details of multiple frameworks, we will introduce <aclass="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v6.3.0.dev88+gf6529fd3a)"><spanclass="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
646
641
<divclass="section" id="pytest-tests">
647
642
<h3><spanclass="section-number">2.7.1. </span>Pytest tests<aclass="headerlink" href="#pytest-tests" title="Permalink to this headline">¶</a></h3>
648
643
<p>A Pytest test is simply a function whose name starts with <codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">test_</span></code>. In
<p>Obtain the <aclass="reference internal" href="not_released.html"><spanclass="doc">skeleton code for these exercises from GitHub classroom</span></a>.
871
881
The skeleton code contains a <codeclass="xref py py-mod docutils literal notranslate"><spanclass="pre">polynomial</span></code> package with a version of
872
882
the <codeclass="xref py py-class docutils literal notranslate"><spanclass="pre">Polynomial</span></code> class.</p>
0 commit comments