Skip to content

Commit 65842dc

Browse files
committed
Dataclass
1 parent c1b93d3 commit 65842dc

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ class C(A, B): pass
872872
```
873873

874874
### Dataclass
875-
**Decorator that automatically generates init(), repr() and eq() magic methods. Object can also be made sortable with `'order=True'` and/or immutable with `'frozen=True'`.**
875+
**Decorator that automatically generates init(), repr() and eq() magic methods.**
876876
```python
877877
from dataclasses import dataclass, field
878878

@@ -882,6 +882,7 @@ class <class_name>:
882882
<attr_name_2>: <type> = <default_value>
883883
<attr_name_3>: list/dict/set = field(default_factory=list/dict/set)
884884
```
885+
* **An object can be made sortable with `'order=True'` or immutable with `'frozen=True'`.**
885886
* **Function field() is needed because `'<attr_name>: list = []'` would make a list that is shared among all instances.**
886887
* **Default_factory can be any callable.**
887888

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ <h3 id="multipleinheritance">Multiple Inheritance</h3>
777777
[&lt;<span class="hljs-class"><span class="hljs-title">class</span> '<span class="hljs-title">C</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]
778778
</span></code></pre>
779779
<h3 id="dataclass">Dataclass</h3>
780-
<p><strong>Decorator that automatically generates init(), repr() and eq() magic methods. Object can also be made sortable with <code class="python hljs"><span class="hljs-string">'order=True'</span></code> and/or immutable with <code class="python hljs"><span class="hljs-string">'frozen=True'</span></code>.</strong></p>
780+
<p><strong>Decorator that automatically generates init(), repr() and eq() magic methods.</strong></p>
781781
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass, field
782782

783783
<span class="hljs-meta">@dataclass(order=False, frozen=False)</span>
@@ -787,6 +787,7 @@ <h3 id="dataclass">Dataclass</h3>
787787
&lt;attr_name_3&gt;: list/dict/set = field(default_factory=list/dict/set)
788788
</code></pre>
789789
<ul>
790+
<li><strong>An object can be made sortable with <code class="python hljs"><span class="hljs-string">'order=True'</span></code> or immutable with <code class="python hljs"><span class="hljs-string">'frozen=True'</span></code>.</strong></li>
790791
<li><strong>Function field() is needed because <code class="python hljs"><span class="hljs-string">'&lt;attr_name&gt;: list = []'</span></code> would make a list that is shared among all instances.</strong></li>
791792
<li><strong>Default_factory can be any callable.</strong></li>
792793
</ul>

0 commit comments

Comments
 (0)