summaryrefslogtreecommitdiff
path: root/devdocs/python~3.12/library%2F__future__.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/python~3.12/library%2F__future__.html')
-rw-r--r--devdocs/python~3.12/library%2F__future__.html40
1 files changed, 40 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2F__future__.html b/devdocs/python~3.12/library%2F__future__.html
new file mode 100644
index 00000000..39cf6cfe
--- /dev/null
+++ b/devdocs/python~3.12/library%2F__future__.html
@@ -0,0 +1,40 @@
+ <span id="future-future-statement-definitions"></span><h1>__future__ — Future statement definitions</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/__future__.py">Lib/__future__.py</a></p> <p><a class="reference internal" href="#module-__future__" title="__future__: Future statement definitions"><code>__future__</code></a> is a real module, and serves three purposes:</p> <ul class="simple"> <li>To avoid confusing existing tools that analyze import statements and expect to find the modules they’re importing.</li> <li>To ensure that <a class="reference internal" href="../reference/simple_stmts#future"><span class="std std-ref">future statements</span></a> run under releases prior to 2.1 at least yield runtime exceptions (the import of <a class="reference internal" href="#module-__future__" title="__future__: Future statement definitions"><code>__future__</code></a> will fail, because there was no module of that name prior to 2.1).</li> <li>To document when incompatible changes were introduced, and when they will be — or were — made mandatory. This is a form of executable documentation, and can be inspected programmatically via importing <a class="reference internal" href="#module-__future__" title="__future__: Future statement definitions"><code>__future__</code></a> and examining its contents.</li> </ul> <span class="target" id="future-classes"></span><dl class="py class"> <dt class="sig sig-object py" id="future__._Feature">
+<code>class __future__._Feature</code> </dt> <dd>
+<p>Each statement in <code>__future__.py</code> is of the form:</p> <pre data-language="python">FeatureName = _Feature(OptionalRelease, MandatoryRelease,
+ CompilerFlag)
+</pre> <p>where, normally, <em>OptionalRelease</em> is less than <em>MandatoryRelease</em>, and both are 5-tuples of the same form as <a class="reference internal" href="sys#sys.version_info" title="sys.version_info"><code>sys.version_info</code></a>:</p> <pre data-language="python">(PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int
+ PY_MINOR_VERSION, # the 1; an int
+ PY_MICRO_VERSION, # the 0; an int
+ PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string
+ PY_RELEASE_SERIAL # the 3; an int
+)
+</pre> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="future__._Feature.getOptionalRelease">
+<code>_Feature.getOptionalRelease()</code> </dt> <dd>
+<p><em>OptionalRelease</em> records the first release in which the feature was accepted.</p> </dd>
+</dl> <dl class="py method"> <dt class="sig sig-object py" id="future__._Feature.getMandatoryRelease">
+<code>_Feature.getMandatoryRelease()</code> </dt> <dd>
+<p>In the case of a <em>MandatoryRelease</em> that has not yet occurred, <em>MandatoryRelease</em> predicts the release in which the feature will become part of the language.</p> <p>Else <em>MandatoryRelease</em> records when the feature became part of the language; in releases at or after that, modules no longer need a future statement to use the feature in question, but may continue to use such imports.</p> <p><em>MandatoryRelease</em> may also be <code>None</code>, meaning that a planned feature got dropped or that it is not yet decided.</p> </dd>
+</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="future__._Feature.compiler_flag">
+<code>_Feature.compiler_flag</code> </dt> <dd>
+<p><em>CompilerFlag</em> is the (bitfield) flag that should be passed in the fourth argument to the built-in function <a class="reference internal" href="functions#compile" title="compile"><code>compile()</code></a> to enable the feature in dynamically compiled code. This flag is stored in the <a class="reference internal" href="#future__._Feature.compiler_flag" title="__future__._Feature.compiler_flag"><code>_Feature.compiler_flag</code></a> attribute on <a class="reference internal" href="#future__._Feature" title="__future__._Feature"><code>_Feature</code></a> instances.</p> </dd>
+</dl> <p>No feature description will ever be deleted from <a class="reference internal" href="#module-__future__" title="__future__: Future statement definitions"><code>__future__</code></a>. Since its introduction in Python 2.1 the following features have found their way into the language using this mechanism:</p> <table class="docutils align-default"> <thead> <tr>
+<th class="head"><p>feature</p></th> <th class="head"><p>optional in</p></th> <th class="head"><p>mandatory in</p></th> <th class="head"><p>effect</p></th> </tr> </thead> <tr>
+<td><p>nested_scopes</p></td> <td><p>2.1.0b1</p></td> <td><p>2.2</p></td> <td><p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0227/"><strong>PEP 227</strong></a>: <em>Statically Nested Scopes</em></p></td> </tr> <tr>
+<td><p>generators</p></td> <td><p>2.2.0a1</p></td> <td><p>2.3</p></td> <td><p><span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-0255/"><strong>PEP 255</strong></a>: <em>Simple Generators</em></p></td> </tr> <tr>
+<td><p>division</p></td> <td><p>2.2.0a2</p></td> <td><p>3.0</p></td> <td><p><span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0238/"><strong>PEP 238</strong></a>: <em>Changing the Division Operator</em></p></td> </tr> <tr>
+<td><p>absolute_import</p></td> <td><p>2.5.0a1</p></td> <td><p>3.0</p></td> <td><p><span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-0328/"><strong>PEP 328</strong></a>: <em>Imports: Multi-Line and Absolute/Relative</em></p></td> </tr> <tr>
+<td><p>with_statement</p></td> <td><p>2.5.0a1</p></td> <td><p>2.6</p></td> <td><p><span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-0343/"><strong>PEP 343</strong></a>: <em>The “with” Statement</em></p></td> </tr> <tr>
+<td><p>print_function</p></td> <td><p>2.6.0a2</p></td> <td><p>3.0</p></td> <td><p><span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-3105/"><strong>PEP 3105</strong></a>: <em>Make print a function</em></p></td> </tr> <tr>
+<td><p>unicode_literals</p></td> <td><p>2.6.0a2</p></td> <td><p>3.0</p></td> <td><p><span class="target" id="index-6"></span><a class="pep reference external" href="https://peps.python.org/pep-3112/"><strong>PEP 3112</strong></a>: <em>Bytes literals in Python 3000</em></p></td> </tr> <tr>
+<td><p>generator_stop</p></td> <td><p>3.5.0b1</p></td> <td><p>3.7</p></td> <td><p><span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0479/"><strong>PEP 479</strong></a>: <em>StopIteration handling inside generators</em></p></td> </tr> <tr>
+<td><p>annotations</p></td> <td><p>3.7.0b1</p></td> <td><p>TBD <a class="footnote-reference brackets" href="#id2" id="id1">1</a></p></td> <td><p><span class="target" id="index-8"></span><a class="pep reference external" href="https://peps.python.org/pep-0563/"><strong>PEP 563</strong></a>: <em>Postponed evaluation of annotations</em></p></td> </tr> </table> <dl class="footnote brackets"> <dt class="label" id="id2">
+<code>1</code> </dt> <dd>
+<p><code>from __future__ import annotations</code> was previously scheduled to become mandatory in Python 3.10, but the Python Steering Council twice decided to delay the change (<a class="reference external" href="https://mail.python.org/archives/list/python-dev@python.org/message/CLVXXPQ2T2LQ5MP2Y53VVQFCXYWQJHKZ/">announcement for Python 3.10</a>; <a class="reference external" href="https://mail.python.org/archives/list/python-dev@python.org/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/">announcement for Python 3.11</a>). No final decision has been made yet. See also <span class="target" id="index-9"></span><a class="pep reference external" href="https://peps.python.org/pep-0563/"><strong>PEP 563</strong></a> and <span class="target" id="index-10"></span><a class="pep reference external" href="https://peps.python.org/pep-0649/"><strong>PEP 649</strong></a>.</p> </dd> </dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt><a class="reference internal" href="../reference/simple_stmts#future"><span class="std std-ref">Future statements</span></a></dt>
+<dd>
+<p>How the compiler treats future imports.</p> </dd> </dl> </div> <div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2001&ndash;2023 Python Software Foundation<br>Licensed under the PSF License.<br>
+ <a href="https://docs.python.org/3.12/library/__future__.html" class="_attribution-link">https://docs.python.org/3.12/library/__future__.html</a>
+ </p>
+</div>