Skip to content

Commit cffe52c

Browse files
committed
Metaprograming
1 parent 23867ed commit cffe52c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,7 @@ Metaprograming
20932093
```
20942094

20952095
### Meta Class
2096-
**Class that creates class.**
2096+
**Class that creates classes.**
20972097

20982098
```python
20992099
def my_meta_class(name, parents, attrs):
@@ -2113,7 +2113,7 @@ class MyMetaClass(type):
21132113
* **New() can also be called directly, usually from a new() method of a child class (**`def __new__(cls): return super().__new__(cls)`**), in which case init() is not called.**
21142114

21152115
### Metaclass Attribute
2116-
**Right before a class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type().**
2116+
**Right before a class is created it checks if it has metaclass attribute defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type().**
21172117

21182118
```python
21192119
class MyClass(metaclass=MyMetaClass):

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@
18241824
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>Z = type(<span class="hljs-string">'Z'</span>, (), {<span class="hljs-string">'a'</span>: <span class="hljs-string">'abcde'</span>, <span class="hljs-string">'b'</span>: <span class="hljs-number">12345</span>})
18251825
<span class="hljs-meta">&gt;&gt;&gt; </span>z = Z()
18261826
</code></pre>
1827-
<div><h3 id="metaclass">Meta Class</h3><p><strong>Class that creates class.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">my_meta_class</span><span class="hljs-params">(name, parents, attrs)</span>:</span>
1827+
<div><h3 id="metaclass">Meta Class</h3><p><strong>Class that creates classes.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">my_meta_class</span><span class="hljs-params">(name, parents, attrs)</span>:</span>
18281828
attrs[<span class="hljs-string">'a'</span>] = <span class="hljs-string">'abcde'</span>
18291829
<span class="hljs-keyword">return</span> type(name, parents, attrs)
18301830
</code></pre></div>
@@ -1841,7 +1841,7 @@
18411841
<li><strong>It receives the same arguments as init(), except for the first one that specifies the desired class of returned instance (MyMetaClass in our case).</strong></li>
18421842
<li><strong>New() can also be called directly, usually from a new() method of a child class (</strong><code class="python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__new__</span><span class="hljs-params">(cls)</span>:</span> <span class="hljs-keyword">return</span> super().__new__(cls)</code><strong>), in which case init() is not called.</strong></li>
18431843
</ul>
1844-
<div><h3 id="metaclassattribute">Metaclass Attribute</h3><p><strong>Right before a class is created it checks if it has metaclass defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type().</strong></p><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span><span class="hljs-params">(metaclass=MyMetaClass)</span>:</span>
1844+
<div><h3 id="metaclassattribute">Metaclass Attribute</h3><p><strong>Right before a class is created it checks if it has metaclass attribute defined. If not, it recursively checks if any of his parents has it defined and eventually comes to type().</strong></p><pre><code class="python language-python hljs"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span><span class="hljs-params">(metaclass=MyMetaClass)</span>:</span>
18451845
b = <span class="hljs-number">12345</span>
18461846
</code></pre></div>
18471847

0 commit comments

Comments
 (0)