From b7d73cb62705808fb79c887e8209dcbb15ba9ad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Wed, 18 May 2022 10:17:21 +0200 Subject: [PATCH] Iterable Duck Types --- README.md | 4 ++++ index.html | 17 +++++++++++------ parse.js | 5 +++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bcc7603..367853c 100644 --- a/README.md +++ b/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().** diff --git a/index.html b/index.html index 1eb7ca1..40fae20 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1096,6 +1096,14 @@ Hello World! +

Discrepancies between glossary definitions and abstract base classes:

+ + + +

ABC Sequence

- - -

Table of required and automatically available special methods:

┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
+

Table of required and automatically available special methods:

┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
 ┃            │  Iterable  │ Collection │  Sequence  │ abc.Sequence ┃
 ┠────────────┼────────────┼────────────┼────────────┼──────────────┨
 ┃ iter()     │     !      │     !      │     ✓      │      ✓       ┃
@@ -2891,7 +2896,7 @@ $ pyinstaller script.py --add-data '<path>:.'  
  
 
   
 
diff --git a/parse.js b/parse.js
index 16a1fbe..c8a117e 100755
--- a/parse.js
+++ b/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'});