Skip to content

Commit 8c1caae

Browse files
committed
Website build
1 parent 3ec91a3 commit 8c1caae

File tree

4 files changed

+98
-20
lines changed

4 files changed

+98
-20
lines changed

11_further_object-oriented_features.html

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,20 @@ <h1><span class="section-number">11. </span>Further object-oriented features<a c
6565
in the course so far.</p>
6666
<div class="section" id="decorators">
6767
<span id="id1"></span><h2><span class="section-number">11.1. </span>Decorators<a class="headerlink" href="#decorators" title="Permalink to this headline"></a></h2>
68-
<p>In <a class="reference internal" href="10_trees_and_directed_acyclic_graphs.html#trees"><span class="std std-numref">Week 10</span></a> we encountered the
68+
<details class="sphinx-bs dropdown card mb-3">
69+
<summary class="summary-title card-header">
70+
Video: decorators.<div class="summary-down docutils">
71+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
72+
<div class="summary-up docutils">
73+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
74+
</summary><div class="summary-content card-body docutils">
75+
<div class="vimeo docutils container">
76+
<iframe src="https://player.vimeo.com/video/526946976"
77+
frameborder="0" allow="autoplay; fullscreen"
78+
allowfullscreen></iframe></div>
79+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=f1d61410-4200-42e5-92c4-acf2011de8ab">watch this video on Panopto</a>.</p>
80+
</div>
81+
</details><p>In <a class="reference internal" href="10_trees_and_directed_acyclic_graphs.html#trees"><span class="std std-numref">Week 10</span></a> we encountered the
6982
<a class="reference external" href="https://docs.python.org/3/library/functools.html#functools.singledispatch" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">functools.singledispatch()</span></code></a> decorator, which turns a function into a
7083
<a class="reference internal" href="10_trees_and_directed_acyclic_graphs.html#term-single-dispatch-function"><span class="xref std std-term">single dispatch function</span></a>. More generally, a decorator is a function
7184
which takes in a function and returns another function. In other words, the
@@ -229,7 +242,20 @@ <h3><span class="section-number">11.1.3. </span>The <a class="reference external
229242
</div>
230243
<div class="section" id="abstract-base-classes">
231244
<span id="id2"></span><h2><span class="section-number">11.2. </span>Abstract base classes<a class="headerlink" href="#abstract-base-classes" title="Permalink to this headline"></a></h2>
232-
<p>We have now on several occasions encountered classes which are not designed to
245+
<details class="sphinx-bs dropdown card mb-3">
246+
<summary class="summary-title card-header">
247+
Video: Abstract base classes.<div class="summary-down docutils">
248+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
249+
<div class="summary-up docutils">
250+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
251+
</summary><div class="summary-content card-body docutils">
252+
<div class="vimeo docutils container">
253+
<iframe src="https://player.vimeo.com/video/526947635"
254+
frameborder="0" allow="autoplay; fullscreen"
255+
allowfullscreen></iframe></div>
256+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=f4678a69-731c-45fe-bdbf-acf2011de880">watch this video on Panopto</a>.</p>
257+
</div>
258+
</details><p>We have now on several occasions encountered classes which are not designed to
233259
be instantiated themselves, but merely serve as parent classes to concrete
234260
classes which are intended to be instantiated. Examples of these classes
235261
include <a class="reference external" href="https://docs.python.org/3/library/numbers.html#numbers.Number" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Number</span></code></a>, <a class="reference internal" href="example_code.html#example_code.groups.Group" title="example_code.groups.Group"><code class="xref py py-class docutils literal notranslate"><span class="pre">example_code.groups.Group</span></code></a>, and the
@@ -426,7 +452,20 @@ <h3><span class="section-number">11.2.3. </span>Duck typing<a class="headerlink"
426452
</div>
427453
<div class="section" id="virtual-subclasses">
428454
<h3><span class="section-number">11.2.4. </span>Virtual subclasses<a class="headerlink" href="#virtual-subclasses" title="Permalink to this headline"></a></h3>
429-
<p>We learned in <a class="reference internal" href="3_objects.html#objects"><span class="std std-numref">Week 3</span></a> that we can determine if a type is a
455+
<details class="sphinx-bs dropdown card mb-3">
456+
<summary class="summary-title card-header">
457+
Video: virtual subclasses.<div class="summary-down docutils">
458+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
459+
<div class="summary-up docutils">
460+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
461+
</summary><div class="summary-content card-body docutils">
462+
<div class="vimeo docutils container">
463+
<iframe src="https://player.vimeo.com/video/526947427"
464+
frameborder="0" allow="autoplay; fullscreen"
465+
allowfullscreen></iframe></div>
466+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=4114bb1d-cc31-4cfc-81a6-acf2011de8d6">watch this video on Panopto</a>.</p>
467+
</div>
468+
</details><p>We learned in <a class="reference internal" href="3_objects.html#objects"><span class="std std-numref">Week 3</span></a> that we can determine if a type is a
430469
number by checking if it is an instance of <a class="reference external" href="https://docs.python.org/3/library/numbers.html#numbers.Number" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Number</span></code></a>. This is a
431470
slightly different usage of abstract base classes. Rather than providing part
432471
of the implementation of, say, <a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">float</span></code></a>, <a class="reference external" href="https://docs.python.org/3/library/numbers.html#numbers.Number" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">numbers.Number</span></code></a> provides
@@ -613,8 +652,7 @@ <h2><span class="section-number">11.3. </span>Glossary<a class="headerlink" href
613652
</div>
614653
<div class="section" id="exercises">
615654
<h2><span class="section-number">11.4. </span>Exercises<a class="headerlink" href="#exercises" title="Permalink to this headline"></a></h2>
616-
<p>Obtain the <a href="#id9"><span class="problematic" id="id10">`skeleton code for these exercises from GitHub classroom
617-
&lt;&gt;`__</span></a>.</p>
655+
<p>Obtain the <a class="reference external" href="https://classroom.github.com/a/qTArFlxP">skeleton code for these exercises from GitHub classroom</a>.</p>
618656
<div class="proof proof-type-exercise" id="id7">
619657

620658
<div class="proof-title">
@@ -629,11 +667,11 @@ <h2><span class="section-number">11.4. </span>Exercises<a class="headerlink" hre
629667
taking any combination of arguments.</p>
630668
<p>The logging itself should be accomplished using
631669
the built-in <a class="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">logging</span></code></a> module by calling <a class="reference external" href="https://docs.python.org/3/library/logging.html#logging.info" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">logging.info()</span></code></a> and passing
632-
the logging message.</p>
633-
<p>The logging message should comprise the function name (accessible using the
634-
<a class="reference external" href="https://docs.python.org/3/reference/import.html#__name__" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__name__</span></code></a> attribute), followed by round brackets containing first the
635-
<a class="reference external" href="https://docs.python.org/3/library/functions.html#repr" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of the positional arguments, followed by the key=value pairs
636-
the keyword arguments.</p>
670+
the log message.</p>
671+
<p>The log message should comprise the string <code class="xref py py-obj docutils literal notranslate"><span class="pre">&quot;Calling:</span> <span class="pre">&quot;</span></code> followed by the
672+
function name (accessible using the <a class="reference external" href="https://docs.python.org/3/reference/import.html#__name__" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__name__</span></code></a> attribute), followed by
673+
round brackets containing first the <a class="reference external" href="https://docs.python.org/3/library/functions.html#repr" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> of the positional
674+
arguments, followed by the key=value pairs the keyword arguments.</p>
637675
</div></div><div class="proof proof-type-exercise" id="id8">
638676

639677
<div class="proof-title">
@@ -643,7 +681,7 @@ <h2><span class="section-number">11.4. </span>Exercises<a class="headerlink" hre
643681
<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">groups.groups</span></code> module in the skeleton code is the new version
644682
introduced above, using an <a class="reference internal" href="#term-abstract-base-class"><span class="xref std std-term">abstract base class</span></a>. The
645683
<code class="xref py py-obj docutils literal notranslate"><span class="pre">log_decorator.log_call</span></code> <a class="reference internal" href="#term-decorator"><span class="xref std std-term">decorator</span></a> has been applied to the
646-
<span class="math notranslate nohighlight">\(Group._validate\)</span> <a class="reference internal" href="#term-abstract-method"><span class="xref std std-term">abstract method</span></a>. However, even once you
684+
<code class="xref py py-meth docutils literal notranslate"><span class="pre">Group._validate()</span></code> <a class="reference internal" href="#term-abstract-method"><span class="xref std std-term">abstract method</span></a>. However, even once you
647685
have implemented this decorator, it never gets called. Your challenge is to
648686
modify <code class="xref py py-mod docutils literal notranslate"><span class="pre">groups.groups</span></code> so that the decorator is called every time a
649687
subclass <code class="xref py py-meth docutils literal notranslate"><span class="pre">_validate()</span></code> method is called, but <strong>without</strong> moving or

_modules/example_code/groups_abc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ <h1>Source code for example_code.groups_abc</h1><div class="highlight"><pre>
124124

125125
<span class="nd">@abstractmethod</span>
126126
<span class="k">def</span> <span class="nf">_validate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
127-
<span class="sd">&quot;&quot;&quot;Ensure that value is a legitimate element value in this group.&quot;&quot;&quot;</span>
127+
<span class="sd">&quot;&quot;&quot;Ensure that value is a legitimate element value in this Group.&quot;&quot;&quot;</span>
128128
<span class="k">pass</span>
129129

130130
<div class="viewcode-block" id="Group.operation"><a class="viewcode-back" href="../../example_code.html#example_code.groups_abc.Group.operation">[docs]</a> <span class="nd">@abstractmethod</span>

_sources/11_further_object-oriented_features.rst.txt

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ in the course so far.
1010
Decorators
1111
----------
1212

13+
.. dropdown:: Video: decorators.
14+
15+
.. container:: vimeo
16+
17+
.. raw:: html
18+
19+
<iframe src="https://player.vimeo.com/video/526946976"
20+
frameborder="0" allow="autoplay; fullscreen"
21+
allowfullscreen></iframe>
22+
23+
Imperial students can also `watch this video on Panopto
24+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=f1d61410-4200-42e5-92c4-acf2011de8ab>`__.
25+
26+
1327
In :numref:`Week %s <trees>` we encountered the
1428
:func:`functools.singledispatch` decorator, which turns a function into a
1529
:term:`single dispatch function`. More generally, a decorator is a function
@@ -193,6 +207,19 @@ ones. We will survey just a few here:
193207
Abstract base classes
194208
---------------------
195209

210+
.. dropdown:: Video: Abstract base classes.
211+
212+
.. container:: vimeo
213+
214+
.. raw:: html
215+
216+
<iframe src="https://player.vimeo.com/video/526947635"
217+
frameborder="0" allow="autoplay; fullscreen"
218+
allowfullscreen></iframe>
219+
220+
Imperial students can also `watch this video on Panopto
221+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=f4678a69-731c-45fe-bdbf-acf2011de880>`__.
222+
196223
We have now on several occasions encountered classes which are not designed to
197224
be instantiated themselves, but merely serve as parent classes to concrete
198225
classes which are intended to be instantiated. Examples of these classes
@@ -363,6 +390,19 @@ second use of abstract base classes comes into play.
363390
Virtual subclasses
364391
~~~~~~~~~~~~~~~~~~
365392

393+
.. dropdown:: Video: virtual subclasses.
394+
395+
.. container:: vimeo
396+
397+
.. raw:: html
398+
399+
<iframe src="https://player.vimeo.com/video/526947427"
400+
frameborder="0" allow="autoplay; fullscreen"
401+
allowfullscreen></iframe>
402+
403+
Imperial students can also `watch this video on Panopto
404+
<https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=4114bb1d-cc31-4cfc-81a6-acf2011de8d6>`__.
405+
366406
We learned in :numref:`Week %s <objects>` that we can determine if a type is a
367407
number by checking if it is an instance of :class:`numbers.Number`. This is a
368408
slightly different usage of abstract base classes. Rather than providing part
@@ -541,7 +581,7 @@ Exercises
541581
---------
542582

543583
Obtain the `skeleton code for these exercises from GitHub classroom
544-
<>`__.
584+
<https://classroom.github.com/a/qTArFlxP>`__.
545585

546586
.. proof:exercise::
547587
@@ -554,19 +594,19 @@ Obtain the `skeleton code for these exercises from GitHub classroom
554594

555595
The logging itself should be accomplished using
556596
the built-in `logging` module by calling :func:`logging.info` and passing
557-
the logging message.
597+
the log message.
558598

559-
The logging message should comprise the function name (accessible using the
560-
`__name__` attribute), followed by round brackets containing first the
561-
:func:`repr` of the positional arguments, followed by the key=value pairs
562-
the keyword arguments.
599+
The log message should comprise the string `"Calling: "` followed by the
600+
function name (accessible using the `__name__` attribute), followed by
601+
round brackets containing first the :func:`repr` of the positional
602+
arguments, followed by the key=value pairs the keyword arguments.
563603

564604
.. proof:exercise::
565605
566606
The :mod:`groups.groups` module in the skeleton code is the new version
567607
introduced above, using an :term:`abstract base class`. The
568608
`log_decorator.log_call` :term:`decorator` has been applied to the
569-
:math:`Group._validate` :term:`abstract method`. However, even once you
609+
:meth:`Group._validate` :term:`abstract method`. However, even once you
570610
have implemented this decorator, it never gets called. Your challenge is to
571611
modify :mod:`groups.groups` so that the decorator is called every time a
572612
subclass :meth:`_validate` method is called, but **without** moving or

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)