Skip to content

Commit 3194abe

Browse files
committed
Introspection rewrite
1 parent ae70273 commit 3194abe

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,25 +2294,25 @@ CRITICAL:my_module:Running out of disk space.
22942294
Introspection
22952295
-------------
22962296
```python
2297-
<list> = dir() # Names of local vars, functions, classes and modules.
2298-
<dict> = vars() # Dict of local vars, functions, etc. Also locals().
2299-
<dict> = globals() # Dict of global vars, etc. (including '__builtins__').
2297+
<list> = dir() # List of of local names (including functions and classes).
2298+
<dict> = vars() # Dict of local names and their objects. Also locals().
2299+
<dict> = globals() # Dict of global names (for instance '__builtin__' module).
23002300
```
23012301

23022302
```python
2303-
<list> = dir(<obj>) # Names of all object's attributes (including methods).
2304-
<dict> = vars(<obj>) # Dict of writable attributes. Also <obj>.__dict__.
2305-
<bool> = hasattr(<obj>, '<attr_name>') # Checks if getattr() raises AttributeError.
2306-
value = getattr(<obj>, '<attr_name>') # Default value can be passed as the third argument.
2307-
setattr(<obj>, '<attr_name>', value) # Only works on objects with __dict__ attribute.
2308-
delattr(<obj>, '<attr_name>') # Same. Also `del <object>.<attr_name>`.
2303+
<list> = dir(<obj>) # Returns names of all object's attributes (incl. methods).
2304+
<dict> = vars(<obj>) # Returns dict of writable attributes. Also <obj>.__dict__.
2305+
<bool> = hasattr(<obj>, '<name>') # Checks if object possesses attribute with passed name.
2306+
value = getattr(<obj>, '<name>') # Returns object's attribute or raises AttributeError.
2307+
setattr(<obj>, '<name>', value) # Sets attribute. Only works on objects with __dict__.
2308+
delattr(<obj>, '<name>') # Deletes attribute from __dict__. Also `del <obj>.<name>`.
23092309
```
23102310

23112311
```python
2312-
<Sig> = inspect.signature(<function>) # Returns function's Signature object.
2313-
<dict> = <Sig>.parameters # Dict of Parameters. Also <Sig>.return_annotation.
2314-
<memb> = <Param>.kind # Member of ParamKind enum (Parameter.KEYWORD_ONLY, …).
2315-
<obj> = <Param>.default # Parameter.empty if missing. Also <Param>.annotation.
2312+
<Sig> = inspect.signature(<func>) # Returns function's Signature object. Can accept a class.
2313+
<dict> = <Sig>.parameters # Returns dict of Parameters. Also <Sig>.return_annotation.
2314+
<memb> = <Param>.kind # Returns ParameterKind member (Parameter.KEYWORD_ONLY, …).
2315+
<type> = <Param>.annotation # Returns Parameter.empty if missing. Also <Param>.default.
23162316
```
23172317

23182318

index.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
<body>
5757
<header>
58-
<aside>October 25, 2024</aside>
58+
<aside>October 26, 2024</aside>
5959
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
6060
</header>
6161

@@ -1877,22 +1877,22 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
18771877
2023-02-07 23:21:01,430 CRITICAL:my_module:Running out of disk space.
18781878
</code></pre></div>
18791879

1880-
<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs">&lt;list&gt; = dir() <span class="hljs-comment"># Names of local vars, functions, classes and modules.</span>
1881-
&lt;dict&gt; = vars() <span class="hljs-comment"># Dict of local vars, functions, etc. Also locals().</span>
1882-
&lt;dict&gt; = globals() <span class="hljs-comment"># Dict of global vars, etc. (including '__builtins__').</span>
1880+
<div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><pre><code class="python language-python hljs">&lt;list&gt; = dir() <span class="hljs-comment"># List of of local names (including functions and classes).</span>
1881+
&lt;dict&gt; = vars() <span class="hljs-comment"># Dict of local names and their objects. Also locals().</span>
1882+
&lt;dict&gt; = globals() <span class="hljs-comment"># Dict of global names (for instance '__builtin__' module).</span>
18831883
</code></pre></div>
18841884

1885-
<pre><code class="python language-python hljs">&lt;list&gt; = dir(&lt;obj&gt;) <span class="hljs-comment"># Names of all object's attributes (including methods).</span>
1886-
&lt;dict&gt; = vars(&lt;obj&gt;) <span class="hljs-comment"># Dict of writable attributes. Also &lt;obj&gt;.__dict__.</span>
1887-
&lt;bool&gt; = hasattr(&lt;obj&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Checks if getattr() raises AttributeError.</span>
1888-
value = getattr(&lt;obj&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Default value can be passed as the third argument.</span>
1889-
setattr(&lt;obj&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>, value) <span class="hljs-comment"># Only works on objects with __dict__ attribute.</span>
1890-
delattr(&lt;obj&gt;, <span class="hljs-string">'&lt;attr_name&gt;'</span>) <span class="hljs-comment"># Same. Also `del &lt;object&gt;.&lt;attr_name&gt;`.</span>
1885+
<pre><code class="python language-python hljs">&lt;list&gt; = dir(&lt;obj&gt;) <span class="hljs-comment"># Returns names of all object's attributes (incl. methods).</span>
1886+
&lt;dict&gt; = vars(&lt;obj&gt;) <span class="hljs-comment"># Returns dict of writable attributes. Also &lt;obj&gt;.__dict__.</span>
1887+
&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>
1888+
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>
1889+
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__.</span>
1890+
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>
18911891
</code></pre>
1892-
<pre><code class="python language-python hljs">&lt;Sig&gt; = inspect.signature(&lt;function&gt;) <span class="hljs-comment"># Returns function's Signature object.</span>
1893-
&lt;dict&gt; = &lt;Sig&gt;.parameters <span class="hljs-comment"># Dict of Parameters. Also &lt;Sig&gt;.return_annotation.</span>
1894-
&lt;memb&gt; = &lt;Param&gt;.kind <span class="hljs-comment"># Member of ParamKind enum (Parameter.KEYWORD_ONLY, …).</span>
1895-
&lt;obj&gt; = &lt;Param&gt;.default <span class="hljs-comment"># Parameter.empty if missing. Also &lt;Param&gt;.annotation.</span>
1892+
<pre><code class="python language-python hljs">&lt;Sig&gt; = inspect.signature(&lt;func&gt;) <span class="hljs-comment"># Returns function's Signature object. Can accept a class.</span>
1893+
&lt;dict&gt; = &lt;Sig&gt;.parameters <span class="hljs-comment"># Returns dict of Parameters. Also &lt;Sig&gt;.return_annotation.</span>
1894+
&lt;memb&gt; = &lt;Param&gt;.kind <span class="hljs-comment"># Returns ParameterKind member (Parameter.KEYWORD_ONLY, …).</span>
1895+
&lt;type&gt; = &lt;Param&gt;.annotation <span class="hljs-comment"># Returns Parameter.empty if missing. Also &lt;Param&gt;.default.</span>
18961896
</code></pre>
18971897
<div><h2 id="coroutines"><a href="#coroutines" name="coroutines">#</a>Coroutines</h2><ul>
18981898
<li><strong>Coroutines have a lot in common with threads, but unlike threads, they only give up control when they call another coroutine and they don’t use as much memory.</strong></li>
@@ -2927,7 +2927,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29272927

29282928

29292929
<footer>
2930-
<aside>October 25, 2024</aside>
2930+
<aside>October 26, 2024</aside>
29312931
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29322932
</footer>
29332933

0 commit comments

Comments
 (0)