GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing python.github.io — __future__ --- Future 陳述式定義 — Python 3.15.2 說明文件
|
功能 |
可選的版本 |
強制性的版本 |
影響 |
|---|---|---|---|
|
2.1.0b1 |
2.2 |
PEP 227: 靜態巢狀作用域 (Statically Nested Scopes) |
|
2.2.0a1 |
2.3 |
PEP 255: 簡單產生器 (Simple Generators) |
|
2.2.0a2 |
3.0 |
PEP 238: 更改除法運算子 (Changing the Division Operator) |
|
2.5.0a1 |
3.0 |
PEP 328: 引入:多列與絕對/相對 (Imports: Multi-Line and Absolute/Relative) |
|
2.5.0a1 |
2.6 |
PEP 343: "with" 陳述式 (The "with" Statement) |
|
2.6.0a2 |
3.0 |
PEP 3105: 使 print 成為一個函式 (Make print a function) |
|
2.6.0a2 |
3.0 |
PEP 3112: Python 3000 中的位元組字面值 (Bytes literals in Python 3000) |
|
3.5.0b1 |
3.7 |
PEP 479: 產生器內部的 StopIteration 處理 (StopIteration handling inside generators) |
|
3.7.0b1 |
從未 [1] |
PEP 563: 註釋的延後求值 (Postponed evaluation of annotations)、PEP 649: 使用描述器延遲求值註釋 (Deferred evaluation of annotations using descriptors) |
__future__.py 中的每個陳述式的形式如下:
FeatureName = _Feature(OptionalRelease, MandatoryRelease, CompilerFlag)
通常,OptionalRelease 會小於 MandatoryRelease,且兩者都是與 sys.version_info 形式相同的 5 元組 (5-tuple):
(PY_MAJOR_VERSION, # 2.1.0a3 裡面的 2;為一整數 PY_MINOR_VERSION, # 1;為一整數 PY_MICRO_VERSION, # 0;為一整數 PY_RELEASE_LEVEL, # "alpha"、"beta"、"candidate" 或 "final"; ;為一字串 PY_RELEASE_SERIAL # 3;為一整數 )
OptionalRelease 記錄該功能首次發布時的 Python 版本。
如果 MandatoryRelease 尚未發布,MandatoryRelease 會預測該功能將成為該語言一部分的版本。
否則 MandatoryRelease 會記錄該功能是何時成為語言的一部分;在該版本或之後的版本中,模組不再需要 future 聲明來使用相關功能,但可以繼續使用此種引入方式。
MandatoryRelease 也可能是 None,這意味著計劃中的功能被丟棄或者仍未決定。
CompilerFlag 是(位元欄位 (bitfield))旗標,應在第四個引數中傳遞給內建函式 compile() 以在動態編譯的程式碼中啟用該功能。此旗標儲存在 _Feature 實例上的 _Feature.compiler_flag 屬性中。
也參考
編譯器如何處理 future 引入。
__future__ 機制的原始提案。