Browse Source

Iterable Duck Types

pull/135/head
Jure Šorn 2 years ago
parent
commit
b7d73cb627
3 changed files with 20 additions and 6 deletions
  1. 4
      README.md
  2. 17
      index.html
  3. 5
      parse.js

4
README.md

@ -1276,6 +1276,10 @@ class MySequence:
return reversed(self.a)
```
#### Discrepancies between glossary definitions and abstract base classes:
* **Glossary defines iterable as any object with iter() or getitem() and sequence as any object with len() and getitem(). It does not define collection.**
* **Passing ABC Iterable to isinstance() or issubclass() checks whether object/class has iter(), while ABC Collection checks for iter(), contains() and len().**
### ABC Sequence
* **It's a richer interface than the basic sequence.**
* **Extending it generates iter(), contains(), reversed(), index() and count().**

17
index.html

@ -54,7 +54,7 @@
<body>
<header>
<aside>May 2, 2022</aside>
<aside>May 18, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</header>
@ -1096,6 +1096,14 @@ Hello World!
</code></pre></div>
<div><h4 id="discrepanciesbetweenglossarydefinitionsandabstractbaseclasses">Discrepancies between glossary definitions and abstract base classes:</h4><ul>
<li><strong>Glossary defines iterable as any object with iter() or getitem() and sequence as any object with len() and getitem(). It does not define collection.</strong></li>
<li><strong>Passing ABC Iterable to isinstance() or issubclass() checks whether object/class has iter(), while ABC Collection checks for iter(), contains() and len().</strong></li>
</ul></div>
<div><h3 id="abcsequence">ABC Sequence</h3><ul>
<li><strong>It's a richer interface than the basic sequence.</strong></li>
<li><strong>Extending it generates iter(), contains(), reversed(), index() and count().</strong></li>
@ -1109,10 +1117,7 @@ Hello World!
<span class="hljs-keyword">return</span> len(self.a)
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__getitem__</span><span class="hljs-params">(self, i)</span>:</span>
<span class="hljs-keyword">return</span> self.a[i]
</code></pre></div>
<div><h4 id="tableofrequiredandautomaticallyavailablespecialmethods">Table of required and automatically available special methods:</h4><pre><code class="text language-text">┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
</code></pre></div><div><h4 id="tableofrequiredandautomaticallyavailablespecialmethods">Table of required and automatically available special methods:</h4><pre><code class="text language-text">┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
┃ │ Iterable │ Collection │ Sequence │ abc.Sequence ┃
┠────────────┼────────────┼────────────┼────────────┼──────────────┨
┃ iter() │ ! │ ! │ ✓ │ ✓ ┃
@ -2891,7 +2896,7 @@ $ pyinstaller script.py --add-data '&lt;path&gt;:.' <span class="hljs-comment">
<footer>
<aside>May 2, 2022</aside>
<aside>May 18, 2022</aside>
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
</footer>

5
parse.js

@ -486,6 +486,7 @@ function modifyPage() {
highlightCode();
fixPandasDiagram();
removePlotImages();
fixABCSequenceDiv();
}
function changeMenu() {
@ -634,6 +635,10 @@ function removePlotImages() {
$('img[alt="Covid Cases"]').remove();
}
function fixABCSequenceDiv() {
$('#abcsequence').parent().insertBefore($('#tableofrequiredandautomaticallyavailablespecialmethods').parent())
}
function updateDate(template) {
const date = new Date();
const date_str = date.toLocaleString('en-us', {month: 'long', day: 'numeric', year: 'numeric'});

Loading…
Cancel
Save