File indexing completed on 2024-04-28 15:53:57
0001 #!/usr/bin/env python2.7 0002 # -*- coding: utf-8 -*- 0003 """:synopsis: Future statement definitions 0004 0005 0006 :mod:`__future__` is a real module, and serves three purposes: 0007 0008 * To avoid confusing existing tools that analyze import statements and expect to 0009 find the modules they're importing. 0010 0011 * To ensure that :ref:`future statements <future>` run under releases prior to 0012 2.1 at least yield runtime exceptions (the import of :mod:`__future__` will 0013 fail, because there was no module of that name prior to 2.1). 0014 0015 * To document when incompatible changes were introduced, and when they will be 0016 --- or were --- made mandatory. This is a form of executable documentation, and 0017 can be inspected programmatically via importing :mod:`__future__` and examining 0018 its contents. 0019 0020 Each statement in :file:`__future__.py` is of the form:: 0021 0022 FeatureName = _Feature(OptionalRelease, MandatoryRelease, 0023 CompilerFlag) 0024 0025 0026 where, normally, *OptionalRelease* is less than *MandatoryRelease*, and both are 0027 5-tuples of the same form as ``sys.version_info``:: 0028 0029 (PY_MAJOR_VERSION, # the 2 in 2.1.0a3; an int 0030 PY_MINOR_VERSION, # the 1; an int 0031 PY_MICRO_VERSION, # the 0; an int 0032 PY_RELEASE_LEVEL, # "alpha", "beta", "candidate" or "final"; string 0033 PY_RELEASE_SERIAL # the 3; an int 0034 ) 0035 0036 *OptionalRelease* records the first release in which the feature was accepted. 0037 0038 In the case of a *MandatoryRelease* that has not yet occurred, 0039 *MandatoryRelease* predicts the release in which the feature will become part of 0040 the language. 0041 0042 Else *MandatoryRelease* records when the feature became part of the language; in 0043 releases at or after that, modules no longer need a future statement to use the 0044 feature in question, but may continue to use such imports. 0045 0046 *MandatoryRelease* may also be ``None``, meaning that a planned feature got 0047 dropped. 0048 0049 Instances of class :class:`_Feature` have two corresponding methods, 0050 :meth:`getOptionalRelease` and :meth:`getMandatoryRelease`. 0051 0052 *CompilerFlag* is the (bitfield) flag that should be passed in the fourth 0053 argument to the built-in function :func:`compile` to enable the feature in 0054 dynamically compiled code. This flag is stored in the :attr:`compiler_flag` 0055 attribute on :class:`_Feature` instances. 0056 0057 No feature description will ever be deleted from :mod:`__future__`. Since its 0058 introduction in Python 2.1 the following features have found their way into the 0059 language using this mechanism: 0060 0061 +------------------+-------------+--------------+---------------------------------------------+ 0062 | feature | optional in | mandatory in | effect | 0063 +==================+=============+==============+=============================================+ 0064 | nested_scopes | 2.1.0b1 | 2.2 | :pep:`227`: | 0065 | | | | *Statically Nested Scopes* | 0066 +------------------+-------------+--------------+---------------------------------------------+ 0067 | generators | 2.2.0a1 | 2.3 | :pep:`255`: | 0068 | | | | *Simple Generators* | 0069 +------------------+-------------+--------------+---------------------------------------------+ 0070 | division | 2.2.0a2 | 3.0 | :pep:`238`: | 0071 | | | | *Changing the Division Operator* | 0072 +------------------+-------------+--------------+---------------------------------------------+ 0073 | absolute_import | 2.5.0a1 | 2.7 | :pep:`328`: | 0074 | | | | *Imports: Multi-Line and Absolute/Relative* | 0075 +------------------+-------------+--------------+---------------------------------------------+ 0076 | with_statement | 2.5.0a1 | 2.6 | :pep:`343`: | 0077 | | | | *The "with" Statement* | 0078 +------------------+-------------+--------------+---------------------------------------------+ 0079 | print_function | 2.6.0a2 | 3.0 | :pep:`3105`: | 0080 | | | | *Make print a function* | 0081 +------------------+-------------+--------------+---------------------------------------------+ 0082 | unicode_literals | 2.6.0a2 | 3.0 | :pep:`3112`: | 0083 | | | | *Bytes literals in Python 3000* | 0084 +------------------+-------------+--------------+---------------------------------------------+ 0085 0086 """ 0087 0088 def nested_scopes(): pass 0089 def generators(): pass 0090 def print_function(): pass 0091 def division(): pass 0092 def absolute_import(): pass 0093 def with_statement(): pass 0094 def unicode_literals(): pass