Skip to content

Commit 80a9eae

Browse files
committed
Imports
1 parent 6e93a7b commit 80a9eae

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,12 @@ import <package>.<module> # Imports a built-in or '<package>/<module>.py'.
829829
* **On a filesystem this corresponds to a directory of Python files with an optional init script.**
830830
* **Running `'import <package>'` does not automatically provide access to the package's modules unless they are explicitly imported in the `'<package>/__init__.py'` script.**
831831
* **Directory of the file that is passed to python command serves as a root of local imports.**
832-
* **For relative imports use `'from .[…][<pkg/module>[.…]] import <obj>'`.**
832+
* **Use relative imports, i.e. `'from .[…][<pkg/mod>[.…]] import <obj>'`, if project has scattered entry points. Another option is to install the whole project by moving its code into 'src' dir, adding ['pyproject.toml'](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#basic-information) to its root, and running `'$ pip3 install -e .'`.**
833833

834834

835835
Closure
836836
-------
837-
**We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns its nested function.**
837+
**We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns its nested function (any value that is referenced from within multiple nested functions gets shared).**
838838

839839
```python
840840
def get_multiplier(a):
@@ -848,7 +848,6 @@ def get_multiplier(a):
848848
>>> multiply_by_3(10)
849849
30
850850
```
851-
* **Any value that is referenced from within multiple nested functions gets shared.**
852851

853852
### Partial
854853
```python
@@ -1318,7 +1317,7 @@ class MyAbcSequence(abc.Sequence):
13181317
+------------+------------+------------+------------+--------------+
13191318
```
13201319
* **Method iter() is required for `'isinstance(<obj>, abc.Iterable)'` to return True, however any object with getitem() will work with any code expecting an iterable.**
1321-
* **MutableSequence, Set, MutableSet, Mapping and MutableMapping ABCs are also extendable. Use `'<abc>.__abstractmethods__'` to get names of required methods.**
1320+
* **MutableSequence, Set, MutableSet, Mapping and MutableMapping ABCs are also ex&shy;tendable. Use `'<abc>.__abstractmethods__'` to get names of required methods.**
13221321

13231322

13241323
Enum

index.html

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

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

@@ -713,9 +713,9 @@
713713
<li><strong>On a filesystem this corresponds to a directory of Python files with an optional init script.</strong></li>
714714
<li><strong>Running <code class="python hljs"><span class="hljs-string">'import &lt;package&gt;'</span></code> does not automatically provide access to the package's modules unless they are explicitly imported in the <code class="python hljs"><span class="hljs-string">'&lt;package&gt;/__init__.py'</span></code> script.</strong></li>
715715
<li><strong>Directory of the file that is passed to python command serves as a root of local imports.</strong></li>
716-
<li><strong>For relative imports use <code class="python hljs"><span class="hljs-string">'from .[…][&lt;pkg/module&gt;[.…]] import &lt;obj&gt;'</span></code>.</strong></li>
716+
<li><strong>Use relative imports, i.e. <code class="python hljs"><span class="hljs-string">'from .[…][&lt;pkg/mod&gt;[.…]] import &lt;obj&gt;'</span></code>, if project has scattered entry points. Another option is to install the whole project by moving its code into 'src' dir, adding <a href="https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#basic-information">'pyproject.toml'</a> to its root, and running <code class="python hljs"><span class="hljs-string">'$ pip3 install -e .'</span></code>.</strong></li>
717717
</ul>
718-
<div><h2 id="closure"><a href="#closure" name="closure">#</a>Closure</h2><p><strong>We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns its nested function.</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_multiplier</span><span class="hljs-params">(a)</span>:</span>
718+
<div><h2 id="closure"><a href="#closure" name="closure">#</a>Closure</h2><p><strong>We have/get a closure in Python when a nested function references a value of its enclosing function and then the enclosing function returns its nested function (any value that is referenced from within multiple nested functions gets shared).</strong></p><pre><code class="python language-python hljs"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_multiplier</span><span class="hljs-params">(a)</span>:</span>
719719
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">out</span><span class="hljs-params">(b)</span>:</span>
720720
<span class="hljs-keyword">return</span> a * b
721721
<span class="hljs-keyword">return</span> out
@@ -726,9 +726,6 @@
726726
<span class="hljs-meta">&gt;&gt;&gt; </span>multiply_by_3(<span class="hljs-number">10</span>)
727727
<span class="hljs-number">30</span>
728728
</code></pre>
729-
<ul>
730-
<li><strong>Any value that is referenced from within multiple nested functions gets shared.</strong></li>
731-
</ul>
732729
<div><h3 id="partial">Partial</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> partial
733730
&lt;function&gt; = partial(&lt;function&gt; [, &lt;arg_1&gt; [, ...]])
734731
</code></pre></div>
@@ -1146,7 +1143,7 @@
11461143

11471144
<ul>
11481145
<li><strong>Method iter() is required for <code class="python hljs"><span class="hljs-string">'isinstance(&lt;obj&gt;, abc.Iterable)'</span></code> to return True, however any object with getitem() will work with any code expecting an iterable.</strong></li>
1149-
<li><strong>MutableSequence, Set, MutableSet, Mapping and MutableMapping ABCs are also extendable. Use <code class="python hljs"><span class="hljs-string">'&lt;abc&gt;.__abstractmethods__'</span></code> to get names of required methods.</strong></li>
1146+
<li><strong>MutableSequence, Set, MutableSet, Mapping and MutableMapping ABCs are also ex­tendable. Use <code class="python hljs"><span class="hljs-string">'&lt;abc&gt;.__abstractmethods__'</span></code> to get names of required methods.</strong></li>
11501147
</ul>
11511148
<div><h2 id="enum"><a href="#enum" name="enum">#</a>Enum</h2><p><strong>Class of named constants called members.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum, auto
11521149
</code></pre></div>
@@ -2938,7 +2935,7 @@ <h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesandmanualalignment
29382935

29392936

29402937
<footer>
2941-
<aside>December 5, 2025</aside>
2938+
<aside>December 10, 2025</aside>
29422939
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
29432940
</footer>
29442941

pdf/remove_links.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
'<strong>This text uses the term collection instead of <a href="#abstractbaseclasses">iterable</a>. For rationale see <a href="#collection">Collection</a>.</strong>': '<strong>This text uses the term collection instead of iterable. For rationale see Collection (p. 18).</strong>',
1313
'<strong>Calling <code class="python hljs"><span class="hljs-string">\'iter(&lt;iter&gt;)\'</span></code> returns unmodified iterator. For details see <a href="#iterator-1">Iterator</a> duck type.</strong>': '<strong>Calling <code class="python hljs"><span class="hljs-string">\'iter(&lt;iter&gt;)\'</span></code> returns unmodified iterator. For details see duck types (p. 17).</strong>',
1414
'<strong>Adding <code class="python hljs"><span class="hljs-string">\'!r\'</span></code> to the expression converts object to string by calling its <a href="#class">repr()</a> method.</strong>': '<strong>Adding <code class="python hljs"><span class="hljs-string">\'!r\'</span></code> to the expression converts object to string by calling its repr() method.</strong>',
15+
'<strong>Use relative imports, i.e. <code class="python hljs"><span class="hljs-string">\'from .[…][&lt;pkg/mod&gt;[.…]] import &lt;obj&gt;\'</span></code>, if project has scattered entry points. Another option is to install the whole project by moving its code into \'src\' dir, adding <a href="https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#basic-information">\'pyproject.toml\'</a> to its root, and running <code class="python hljs"><span class="hljs-string">\'$ pip3 install -e .\'</span></code>.</strong>': '<strong>Use relative imports, i.e. <code class="python hljs"><span class="hljs-string">\'from .[…][&lt;pkg/mod&gt;[.…]] import &lt;obj&gt;\'</span></code>, if project has scattered entry points. Another option is to install the whole project by moving its code into \'src\' dir, adding \'pyproject.toml\' to its root, and running <code class="python hljs"><span class="hljs-string">\'$ pip3 install -e .\'</span></code>.</strong>',
1516
'<strong>A decorator takes a function, adds some functionality and returns it. It can be any <a href="#callable">callable</a>, but is usually implemented as a function that returns a <a href="#closure">closure</a>.</strong>': '<strong>A decorator takes a function, adds some functionality and returns it. It can be any callable (p.&nbsp;17), but is usually implemented as a function that returns a closure.</strong>',
1617
'<strong>Hints are used by type checkers like <a href="https://pypi.org/project/mypy/">mypy</a>, data validation libraries such as <a href="https://pypi.org/project/pydantic/">Pydantic</a> and lately also by <a href="https://pypi.org/project/Cython/">Cython</a> compiler. However, they are not enforced by CPython interpreter.</strong>': '<strong>Hints are used by type checkers like mypy, data validation libraries such as Pydantic and lately also by Cython compiler. However, they are not enforced by CPython interpreter.</strong>',
1718
'<strong>Objects can be made <a href="#sortable">sortable</a> with <code class="python hljs"><span class="hljs-string">\'order=True\'</span></code> and immutable with <code class="python hljs"><span class="hljs-string">\'frozen=True\'</span></code>.</strong>': '<strong>Objects can be made sortable with <code class="python hljs"><span class="hljs-string">\'order=True\'</span></code> and immutable with <code class="python hljs"><span class="hljs-string">\'frozen=True\'</span></code>.</strong>',

0 commit comments

Comments
 (0)