Skip to content

Commit f6f7ceb

Browse files
committed
Class, Iterable duck types
1 parent 8a82210 commit f6f7ceb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ class <name>:
967967
* **If only repr() is defined, it will also be used for str().**
968968
* **Methods decorated with `'@staticmethod'` do not receive 'self' nor 'cls' as their first arg.**
969969

970-
#### Str() use cases:
970+
#### Expressions that call the str() method:
971971
```python
972972
print(<el>)
973973
f'{<el>}'
@@ -976,7 +976,7 @@ csv.writer(<file>).writerow([<el>])
976976
raise Exception(<el>)
977977
```
978978

979-
#### Repr() use cases:
979+
#### Expressions that call the repr() method:
980980
```python
981981
print/str/repr([<el>])
982982
f'{<el>!r}'
@@ -1261,7 +1261,7 @@ class MyCollection:
12611261
* **Only required methods are len() and getitem().**
12621262
* **Getitem() should return an item at the passed index or raise IndexError.**
12631263
* **Iter() and contains() automatically work on any object that has getitem() defined.**
1264-
* **Reversed() automatically works on any object that has len() and getitem() defined.**
1264+
* **Reversed() automatically works on any object that has getitem() and len() defined.**
12651265
```python
12661266
class MySequence:
12671267
def __init__(self, a):

index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,14 @@
827827
<li><strong>If only repr() is defined, it will also be used for str().</strong></li>
828828
<li><strong>Methods decorated with <code class="python hljs"><span class="hljs-string">'@staticmethod'</span></code> do not receive 'self' nor 'cls' as their first arg.</strong></li>
829829
</ul>
830-
<div><h4 id="strusecases">Str() use cases:</h4><pre><code class="python language-python hljs">print(&lt;el&gt;)
830+
<div><h4 id="expressionsthatcallthestrmethod">Expressions that call the str() method:</h4><pre><code class="python language-python hljs">print(&lt;el&gt;)
831831
<span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;}</span>'</span>
832832
logging.warning(&lt;el&gt;)
833833
csv.writer(&lt;file&gt;).writerow([&lt;el&gt;])
834834
<span class="hljs-keyword">raise</span> Exception(&lt;el&gt;)
835835
</code></pre></div>
836836

837-
<div><h4 id="reprusecases">Repr() use cases:</h4><pre><code class="python language-python hljs">print/str/repr([&lt;el&gt;])
837+
<div><h4 id="expressionsthatcallthereprmethod">Expressions that call the repr() method:</h4><pre><code class="python language-python hljs">print/str/repr([&lt;el&gt;])
838838
<span class="hljs-string">f'<span class="hljs-subst">{&lt;el&gt;!r}</span>'</span>
839839
Z = dataclasses.make_dataclass(<span class="hljs-string">'Z'</span>, [<span class="hljs-string">'a'</span>]); print/str/repr(Z(&lt;el&gt;))
840840
<span class="hljs-meta">&gt;&gt;&gt; </span>&lt;el&gt;
@@ -1080,7 +1080,7 @@
10801080
<li><strong>Only required methods are len() and getitem().</strong></li>
10811081
<li><strong>Getitem() should return an item at the passed index or raise IndexError.</strong></li>
10821082
<li><strong>Iter() and contains() automatically work on any object that has getitem() defined.</strong></li>
1083-
<li><strong>Reversed() automatically works on any object that has len() and getitem() defined.</strong></li>
1083+
<li><strong>Reversed() automatically works on any object that has getitem() and len() defined.</strong></li>
10841084
</ul><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MySequence</span>:</span>
10851085
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, a)</span>:</span>
10861086
self.a = a

0 commit comments

Comments
 (0)