From cf5103b050c45ece4626a0cf1b4be7ca4c469db1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 15 Mar 2024 05:35:16 +0100 Subject: [PATCH] Iterable Duck Types --- README.md | 5 +++-- index.html | 5 +++-- parse.js | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a6fd74e..6b1ed97 100644 --- a/README.md +++ b/README.md @@ -1309,7 +1309,7 @@ class MyAbcSequence(abc.Sequence): +------------+------------+------------+------------+--------------+ | | Iterable | Collection | Sequence | abc.Sequence | +------------+------------+------------+------------+--------------+ -| iter() | REQ | REQ | Yes | Yes | +| iter() | REQ* | REQ | Yes | Yes | | contains() | Yes | Yes | Yes | Yes | | len() | | REQ | REQ | REQ | | getitem() | | | REQ | REQ | @@ -1318,7 +1318,8 @@ class MyAbcSequence(abc.Sequence): | count() | | | | Yes | +------------+------------+------------+------------+--------------+ ``` -* **Other ABCs that generate missing methods are: MutableSequence, Set, MutableSet, Mapping and MutableMapping.** +* **Method iter() is required for `'isinstance(, abc.Iterable)'` to return True, however any object with getitem() will work just fine with any code expecting an iterable.** +* **Abstract base classes that generate missing methods when extended are: Sequence, MutableSequence, Set, MutableSet, Mapping and MutableMapping.** * **Names of their required methods are stored in `'.__abstractmethods__'`.** diff --git a/index.html b/index.html index c6eb51c..2cbc803 100644 --- a/index.html +++ b/index.html @@ -1120,7 +1120,7 @@ Hello World!

Table of required and automatically available special methods:

┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
 ┃            │  Iterable  │ Collection │  Sequence  │ abc.Sequence ┃
 ┠────────────┼────────────┼────────────┼────────────┼──────────────┨
-┃ iter()     │     !      │     !      │     ✓      │      ✓       ┃
+┃ iter()     │     !*     │     !      │     ✓      │      ✓       ┃
 ┃ contains() │     ✓      │     ✓      │     ✓      │      ✓       ┃
 ┃ len()      │            │     !      │     !      │      !       ┃
 ┃ getitem()  │            │            │     !      │      !       ┃
@@ -1131,7 +1131,8 @@ Hello World!
 
    -
  • Other ABCs that generate missing methods are: MutableSequence, Set, MutableSet, Mapping and MutableMapping.
  • +
  • Method iter() is required for 'isinstance(<obj>, abc.Iterable)' to return True, however any object with getitem() will work just fine with any code expecting an iterable.
  • +
  • Abstract base classes that generate missing methods when extended are: Sequence, MutableSequence, Set, MutableSet, Mapping and MutableMapping.
  • Names of their required methods are stored in '<abc>.__abstractmethods__'.

#Enum

from enum import Enum, auto
diff --git a/parse.js b/parse.js
index d99d15c..cd32aa2 100755
--- a/parse.js
+++ b/parse.js
@@ -410,7 +410,7 @@ const DIAGRAM_6_B =
   '┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓\n' +
   '┃            │  Iterable  │ Collection │  Sequence  │ abc.Sequence ┃\n' +
   '┠────────────┼────────────┼────────────┼────────────┼──────────────┨\n' +
-  '┃ iter()     │     !      │     !      │     ✓      │      ✓       ┃\n' +
+  '┃ iter()     │     !*     │     !      │     ✓      │      ✓       ┃\n' +
   '┃ contains() │     ✓      │     ✓      │     ✓      │      ✓       ┃\n' +
   '┃ len()      │            │     !      │     !      │      !       ┃\n' +
   '┃ getitem()  │            │            │     !      │      !       ┃\n' +