17db96d56Sopenharmony_ci:mod:`__future__` --- Future statement definitions 27db96d56Sopenharmony_ci================================================== 37db96d56Sopenharmony_ci 47db96d56Sopenharmony_ci.. module:: __future__ 57db96d56Sopenharmony_ci :synopsis: Future statement definitions 67db96d56Sopenharmony_ci 77db96d56Sopenharmony_ci**Source code:** :source:`Lib/__future__.py` 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci-------------- 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci:mod:`__future__` is a real module, and serves three purposes: 127db96d56Sopenharmony_ci 137db96d56Sopenharmony_ci* To avoid confusing existing tools that analyze import statements and expect to 147db96d56Sopenharmony_ci find the modules they're importing. 157db96d56Sopenharmony_ci 167db96d56Sopenharmony_ci* To ensure that :ref:`future statements <future>` run under releases prior to 177db96d56Sopenharmony_ci 2.1 at least yield runtime exceptions (the import of :mod:`__future__` will 187db96d56Sopenharmony_ci fail, because there was no module of that name prior to 2.1). 197db96d56Sopenharmony_ci 207db96d56Sopenharmony_ci* To document when incompatible changes were introduced, and when they will be 217db96d56Sopenharmony_ci --- or were --- made mandatory. This is a form of executable documentation, and 227db96d56Sopenharmony_ci can be inspected programmatically via importing :mod:`__future__` and examining 237db96d56Sopenharmony_ci its contents. 247db96d56Sopenharmony_ci 257db96d56Sopenharmony_ciEach statement in :file:`__future__.py` is of the form:: 267db96d56Sopenharmony_ci 277db96d56Sopenharmony_ci FeatureName = _Feature(OptionalRelease, MandatoryRelease, 287db96d56Sopenharmony_ci CompilerFlag) 297db96d56Sopenharmony_ci 307db96d56Sopenharmony_ci 317db96d56Sopenharmony_ciwhere, normally, *OptionalRelease* is less than *MandatoryRelease*, and both are 327db96d56Sopenharmony_ci5-tuples of the same form as :data:`sys.version_info`:: 337db96d56Sopenharmony_ci 347db96d56Sopenharmony_ci (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int 357db96d56Sopenharmony_ci PY_MINOR_VERSION, # the 1; an int 367db96d56Sopenharmony_ci PY_MICRO_VERSION, # the 0; an int 377db96d56Sopenharmony_ci PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string 387db96d56Sopenharmony_ci PY_RELEASE_SERIAL # the 3; an int 397db96d56Sopenharmony_ci ) 407db96d56Sopenharmony_ci 417db96d56Sopenharmony_ci*OptionalRelease* records the first release in which the feature was accepted. 427db96d56Sopenharmony_ci 437db96d56Sopenharmony_ciIn the case of a *MandatoryRelease* that has not yet occurred, 447db96d56Sopenharmony_ci*MandatoryRelease* predicts the release in which the feature will become part of 457db96d56Sopenharmony_cithe language. 467db96d56Sopenharmony_ci 477db96d56Sopenharmony_ciElse *MandatoryRelease* records when the feature became part of the language; in 487db96d56Sopenharmony_cireleases at or after that, modules no longer need a future statement to use the 497db96d56Sopenharmony_cifeature in question, but may continue to use such imports. 507db96d56Sopenharmony_ci 517db96d56Sopenharmony_ci*MandatoryRelease* may also be ``None``, meaning that a planned feature got 527db96d56Sopenharmony_cidropped. 537db96d56Sopenharmony_ci 547db96d56Sopenharmony_ciInstances of class :class:`_Feature` have two corresponding methods, 557db96d56Sopenharmony_ci:meth:`getOptionalRelease` and :meth:`getMandatoryRelease`. 567db96d56Sopenharmony_ci 577db96d56Sopenharmony_ci*CompilerFlag* is the (bitfield) flag that should be passed in the fourth 587db96d56Sopenharmony_ciargument to the built-in function :func:`compile` to enable the feature in 597db96d56Sopenharmony_cidynamically compiled code. This flag is stored in the :attr:`compiler_flag` 607db96d56Sopenharmony_ciattribute on :class:`_Feature` instances. 617db96d56Sopenharmony_ci 627db96d56Sopenharmony_ciNo feature description will ever be deleted from :mod:`__future__`. Since its 637db96d56Sopenharmony_ciintroduction in Python 2.1 the following features have found their way into the 647db96d56Sopenharmony_cilanguage using this mechanism: 657db96d56Sopenharmony_ci 667db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 677db96d56Sopenharmony_ci| feature | optional in | mandatory in | effect | 687db96d56Sopenharmony_ci+==================+=============+==============+=============================================+ 697db96d56Sopenharmony_ci| nested_scopes | 2.1.0b1 | 2.2 | :pep:`227`: | 707db96d56Sopenharmony_ci| | | | *Statically Nested Scopes* | 717db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 727db96d56Sopenharmony_ci| generators | 2.2.0a1 | 2.3 | :pep:`255`: | 737db96d56Sopenharmony_ci| | | | *Simple Generators* | 747db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 757db96d56Sopenharmony_ci| division | 2.2.0a2 | 3.0 | :pep:`238`: | 767db96d56Sopenharmony_ci| | | | *Changing the Division Operator* | 777db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 787db96d56Sopenharmony_ci| absolute_import | 2.5.0a1 | 3.0 | :pep:`328`: | 797db96d56Sopenharmony_ci| | | | *Imports: Multi-Line and Absolute/Relative* | 807db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 817db96d56Sopenharmony_ci| with_statement | 2.5.0a1 | 2.6 | :pep:`343`: | 827db96d56Sopenharmony_ci| | | | *The "with" Statement* | 837db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 847db96d56Sopenharmony_ci| print_function | 2.6.0a2 | 3.0 | :pep:`3105`: | 857db96d56Sopenharmony_ci| | | | *Make print a function* | 867db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 877db96d56Sopenharmony_ci| unicode_literals | 2.6.0a2 | 3.0 | :pep:`3112`: | 887db96d56Sopenharmony_ci| | | | *Bytes literals in Python 3000* | 897db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 907db96d56Sopenharmony_ci| generator_stop | 3.5.0b1 | 3.7 | :pep:`479`: | 917db96d56Sopenharmony_ci| | | | *StopIteration handling inside generators* | 927db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 937db96d56Sopenharmony_ci| annotations | 3.7.0b1 | TBD [1]_ | :pep:`563`: | 947db96d56Sopenharmony_ci| | | | *Postponed evaluation of annotations* | 957db96d56Sopenharmony_ci+------------------+-------------+--------------+---------------------------------------------+ 967db96d56Sopenharmony_ci 977db96d56Sopenharmony_ci.. XXX Adding a new entry? Remember to update simple_stmts.rst, too. 987db96d56Sopenharmony_ci 997db96d56Sopenharmony_ci.. [1] 1007db96d56Sopenharmony_ci ``from __future__ import annotations`` was previously scheduled to 1017db96d56Sopenharmony_ci become mandatory in Python 3.10, but the Python Steering Council 1027db96d56Sopenharmony_ci twice decided to delay the change 1037db96d56Sopenharmony_ci (`announcement for Python 3.10 <https://mail.python.org/archives/list/python-dev@python.org/message/CLVXXPQ2T2LQ5MP2Y53VVQFCXYWQJHKZ/>`__; 1047db96d56Sopenharmony_ci `announcement for Python 3.11 <https://mail.python.org/archives/list/python-dev@python.org/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/>`__). 1057db96d56Sopenharmony_ci No final decision has been made yet. See also :pep:`563` and :pep:`649`. 1067db96d56Sopenharmony_ci 1077db96d56Sopenharmony_ci 1087db96d56Sopenharmony_ci.. seealso:: 1097db96d56Sopenharmony_ci 1107db96d56Sopenharmony_ci :ref:`future` 1117db96d56Sopenharmony_ci How the compiler treats future imports. 112