Skip to content

Commit fc2c3f7

Browse files
committed
Match statement, Introspection
1 parent 39ca9bc commit fc2c3f7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,7 +2144,7 @@ match <object/expression>:
21442144
* **Sequence pattern can also be written as a tuple, either with or without the brackets.**
21452145
* **Use `'*<name>'` and `'**<name>'` in sequence/mapping patterns to bind remaining items.**
21462146
* **Sequence pattern must match all items of the collection, while mapping pattern does not.**
2147-
* **Patterns can be surrounded with brackets to override their precedence: `'|'` > `'as'` > `','`. For example, `'[1, 2]'` gets caught by the `'case 1 | 0, 2 as x if x == 2'` clause.**
2147+
* **Patterns can be surrounded with brackets to override their precedence: `'|'` > `'as'` > `','`. For example, `'[1, 2]'` gets caught by the `'case 1|2, 2|3 as x if x == 2:'` clause.**
21482148
* **All names that are bound in the matching case, as well as variables initialized in its block, are visible after the match statement (only the function block delimits scope).**
21492149

21502150
### Example
@@ -2226,13 +2226,13 @@ Introspection
22262226
<list> = dir(<obj>) # Returns names of object's attributes (including methods).
22272227
<dict> = vars(<obj>) # Returns dict of writable attributes. Also <obj>.__dict__.
22282228
<bool> = hasattr(<obj>, '<name>') # Checks if object possesses attribute with passed name.
2229-
value = getattr(<obj>, '<name>') # Returns object's attribute or raises AttributeError.
2229+
value = getattr(<obj>, '<name>') # Returns the object's attribute or raises AttributeError.
22302230
setattr(<obj>, '<name>', value) # Sets attribute. Only works on objects with __dict__ attr.
22312231
delattr(<obj>, '<name>') # Deletes attribute from __dict__. Also `del <obj>.<name>`.
22322232
```
22332233

22342234
```python
2235-
<Sig> = inspect.signature(<func>) # Returns a Signature object of the passed function.
2235+
<Sig> = inspect.signature(<func>) # Returns Signature object of the passed function or class.
22362236
<dict> = <Sig>.parameters # Returns dict of Parameters. Also <Sig>.return_annotation.
22372237
<memb> = <Param>.kind # Returns ParameterKind member (Parameter.KEYWORD_ONLY, …).
22382238
<type> = <Param>.annotation # Returns Parameter.empty if missing. Also <Param>.default.

index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
<body>
5858
<header>
59-
<aside>July 30, 2025</aside>
59+
<aside>July 31, 2025</aside>
6060
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6161
</header>
6262

@@ -1775,7 +1775,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
17751775
<li><strong>Sequence pattern can also be written as a tuple, either with or without the brackets.</strong></li>
17761776
<li><strong>Use <code class="python hljs"><span class="hljs-string">'*&lt;name&gt;'</span></code> and <code class="python hljs"><span class="hljs-string">'**&lt;name&gt;'</span></code> in sequence/mapping patterns to bind remaining items.</strong></li>
17771777
<li><strong>Sequence pattern must match all items of the collection, while mapping pattern does not.</strong></li>
1778-
<li><strong>Patterns can be surrounded with brackets to override their precedence: <code class="python hljs"><span class="hljs-string">'|'</span></code> &gt; <code class="python hljs"><span class="hljs-string">'as'</span></code> &gt; <code class="python hljs"><span class="hljs-string">','</span></code>. For example, <code class="python hljs"><span class="hljs-string">'[1, 2]'</span></code> gets caught by the <code class="python hljs"><span class="hljs-string">'case 1 | 0, 2 as x if x == 2'</span></code> clause.</strong></li>
1778+
<li><strong>Patterns can be surrounded with brackets to override their precedence: <code class="python hljs"><span class="hljs-string">'|'</span></code> &gt; <code class="python hljs"><span class="hljs-string">'as'</span></code> &gt; <code class="python hljs"><span class="hljs-string">','</span></code>. For example, <code class="python hljs"><span class="hljs-string">'[1, 2]'</span></code> gets caught by the <code class="python hljs"><span class="hljs-string">'case 1|2, 2|3 as x if x == 2:'</span></code> clause.</strong></li>
17791779
<li><strong>All names that are bound in the matching case, as well as variables initialized in its block, are visible after the match statement (only the function block delimits scope).</strong></li>
17801780
</ul>
17811781
<div><h3 id="example-2">Example</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path
@@ -1840,11 +1840,11 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
18401840
<pre><code class="python language-python hljs">&lt;list&gt; = dir(&lt;obj&gt;) <span class="hljs-comment"># Returns names of object's attributes (including methods).</span>
18411841
&lt;dict&gt; = vars(&lt;obj&gt;) <span class="hljs-comment"># Returns dict of writable attributes. Also &lt;obj&gt;.__dict__.</span>
18421842
&lt;bool&gt; = hasattr(&lt;obj&gt;, <span class="hljs-string">'&lt;name&gt;'</span>) <span class="hljs-comment"># Checks if object possesses attribute with passed name.</span>
1843-
value = getattr(&lt;obj&gt;, <span class="hljs-string">'&lt;name&gt;'</span>) <span class="hljs-comment"># Returns object's attribute or raises AttributeError.</span>
1843+
value = getattr(&lt;obj&gt;, <span class="hljs-string">'&lt;name&gt;'</span>) <span class="hljs-comment"># Returns the object's attribute or raises AttributeError.</span>
18441844
setattr(&lt;obj&gt;, <span class="hljs-string">'&lt;name&gt;'</span>, value) <span class="hljs-comment"># Sets attribute. Only works on objects with __dict__ attr.</span>
18451845
delattr(&lt;obj&gt;, <span class="hljs-string">'&lt;name&gt;'</span>) <span class="hljs-comment"># Deletes attribute from __dict__. Also `del &lt;obj&gt;.&lt;name&gt;`.</span>
18461846
</code></pre>
1847-
<pre><code class="python language-python hljs">&lt;Sig&gt; = inspect.signature(&lt;func&gt;) <span class="hljs-comment"># Returns a Signature object of the passed function.</span>
1847+
<pre><code class="python language-python hljs">&lt;Sig&gt; = inspect.signature(&lt;func&gt;) <span class="hljs-comment"># Returns Signature object of the passed function or class.</span>
18481848
&lt;dict&gt; = &lt;Sig&gt;.parameters <span class="hljs-comment"># Returns dict of Parameters. Also &lt;Sig&gt;.return_annotation.</span>
18491849
&lt;memb&gt; = &lt;Param&gt;.kind <span class="hljs-comment"># Returns ParameterKind member (Parameter.KEYWORD_ONLY, …).</span>
18501850
&lt;type&gt; = &lt;Param&gt;.annotation <span class="hljs-comment"># Returns Parameter.empty if missing. Also &lt;Param&gt;.default.</span>
@@ -2934,7 +2934,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29342934

29352935

29362936
<footer>
2937-
<aside>July 30, 2025</aside>
2937+
<aside>July 31, 2025</aside>
29382938
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29392939
</footer>
29402940

0 commit comments

Comments
 (0)