From 430d346eaa8bc79bb273c354ebcc8f1e48ccb698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 8 Jul 2019 22:20:57 +0200 Subject: [PATCH] Iterable duck types --- README.md | 4 +++- index.html | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 84f0bd8..4f44d1b 100644 --- a/README.md +++ b/README.md @@ -1101,6 +1101,8 @@ class MySortable: ``` ### Iterator +* **Next() should return next item or raise 'StopIteration'.** +* **Iter() should return 'self'.** ```python class Counter: def __init__(self): @@ -1205,7 +1207,7 @@ class MyCollection: ``` ### Sequence -* **Only required methods are len() and getitem().** +* **Only required methods are len() and getitem(), that should return an item at index or raise 'IndexError'.** * **Iter() and contains() automatically work on any object that has getitem() defined.** * **Reversed() automatically works on any object that has getitem() and len() defined.** ```python diff --git a/index.html b/index.html index e260b27..bb91ed6 100644 --- a/index.html +++ b/index.html @@ -1034,6 +1034,10 @@ Z = dataclasses.make_dataclass('Z', [return NotImplemented

Iterator

+
class Counter:
     def __init__(self):
         self.i = 0
@@ -1120,7 +1124,7 @@ lock = threading.RLock(); with lock: ...
 

Sequence