"__future__" --- future 文の定義
********************************

**ソースコード:** Lib/__future__.py

======================================================================

"from __future__ import feature" の形式でのインポートは future 文 の定
義と呼ばれています。これらは特殊なケースで、 Python の新機能が標準にな
るリリースの前に Python コンパイラーが future 文を含むモジュールで
Python の新機能を使用できるようにします。

これらの future 文が Python コンパイラーによって追加の特殊な意味を与え
られる一方で、それらは依然として他のインポート文のように実行され、
"__future__" は存在し、他の Python モジュールと同じようにインポートシ
ステムによって処理されます。この設計は3つの目的にかなっています:

* import 文を解析する既存のツールを混乱させることを避け、インポートし
  ようとしているモジュールを見つけられるようにするため。

* 互換性のない変化がいつ言語に導入され、いつ言語の一部になる --- ある
  いは、なった --- のかを文書化するため。これは実行できる形式で書かれ
  たドキュメントなので、 "__future__" をインポートしてその中身を調べる
  ことでプログラムから調査することができます。

* Python 2.1 以前のリリースで future 文 が実行された場合に、最低でもラ
  ンタイム例外を投げるようにするため ("__future__" のインポートは失敗
  します。なぜなら、 2.1 以前にはそういう名前のモジュールはなかったか
  らです)。


モジュールコンテンツ
====================

機能の記述が "__future__" から削除されたことはまだありません。 Python
2.1 で future 文が導入されて以来、この仕組みを使って以下の機能が言語に
導入されてきました:

+---------------------------+---------------------------+---------------------------+---------------------------+
| feature                   | optional in               | mandatory in              | effect                    |
|===========================|===========================|===========================|===========================|
| __future__.nested_scopes  | 2.1.0b1                   | 2.2                       | **PEP 227**: *Statically  |
|                           |                           |                           | Nested Scopes*            |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.generators     | 2.2.0a1                   | 2.3                       | **PEP 255**: *Simple      |
|                           |                           |                           | Generators*               |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.division       | 2.2.0a2                   | 3.0                       | **PEP 238**: *Changing    |
|                           |                           |                           | the Division Operator*    |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.absolute_impo  | 2.5.0a1                   | 3.0                       | **PEP 328**: *Imports:    |
| rt                        |                           |                           | Multi-Line and            |
|                           |                           |                           | Absolute/Relative*        |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.with_statement | 2.5.0a1                   | 2.6                       | **PEP 343**: *The “with”  |
|                           |                           |                           | Statement*                |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.print_function | 2.6.0a2                   | 3.0                       | **PEP 3105**: *Make print |
|                           |                           |                           | a function*               |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.unicode_liter  | 2.6.0a2                   | 3.0                       | **PEP 3112**: *Bytes      |
| als                       |                           |                           | literals in Python 3000*  |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.generator_stop | 3.5.0b1                   | 3.7                       | **PEP 479**:              |
|                           |                           |                           | *StopIteration handling   |
|                           |                           |                           | inside generators*        |
+---------------------------+---------------------------+---------------------------+---------------------------+
| __future__.annotations    | 3.7.0b1                   | Never [1]                 | **PEP 563**: *Postponed   |
|                           |                           |                           | evaluation of             |
|                           |                           |                           | annotations*, **PEP       |
|                           |                           |                           | 649**: *Deferred          |
|                           |                           |                           | evaluation of annotations |
|                           |                           |                           | using descriptors*        |
+---------------------------+---------------------------+---------------------------+---------------------------+

class __future__._Feature

   "__future__.py" のそれぞれの文は次のような形式をしています:

      FeatureName = _Feature(OptionalRelease, MandatoryRelease,
                             CompilerFlag)

   ここで、普通は、 *OptionalRelease* は *MandatoryRelease* より小さく
   、2つとも "sys.version_info" と同じフォーマットの5つのタプルからな
   ります:

      (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
      )

_Feature.getOptionalRelease()

   *OptionalRelease* はその機能が導入された最初のリリースを記録します
   。

_Feature.getMandatoryRelease()

   まだ時期が来ていない *MandatoryRelease* の場合、*MandatoryRelease*
   はその機能が言語の一部となるリリースを記します。

   その他の場合、*MandatoryRelease* はその機能がいつ言語の一部になった
   のかを記録します。そのリリースから、あるいはそれ以降のリリースでは
   、この機能を使う際に future 文は必要ではありませんが、future 文を使
   い続けても構いません。

   *MandatoryRelease* は "None" になるかもしれません。つまり、予定され
   た機能が破棄されたか、まだ決定されていないということです。

_Feature.compiler_flag

   *CompilerFlag* は、動的にコンパイルされるコードでその機能を有効にす
   るために、組み込み関数 "compile()" の第4引数に渡す(ビットフィールド
   )フラグです。このフラグは "_Feature" インスタンスの
   "_Feature.compiler_flag" 属性に保存されています。

[1] "from __future__ import annotations" was previously scheduled to
    become mandatory in Python 3.10, but the change was delayed and
    ultimately canceled. This feature will eventually be deprecated
    and removed. See **PEP 649** and **PEP 749**.

参考:

  future 文 (future statement)
     コンパイラがどのように future インポートを扱うか。

  **PEP 236** - Back to the __future__
     __future__ 機構の原案
