Python 3.15 中待移除的項目¶
http.server.CGIHTTPRequestHandler
將會被移除,連同其相關的--cgi
旗標到python -m http.server
。它已經過時且很少被使用。沒有直接的替代方案。任何東西都比 CGI 更好的來介接一個帶有請求處理器的網頁伺服器。-
load_module()
method: useexec_module()
instead.
locale
:locale.getdefaultlocale()
已在 Python 3.11 中被棄用,原本計劃在 Python 3.13 中移除 (gh-90817),但被延後至 Python 3.15。請改用locale.setlocale()
、locale.getencoding()
和locale.getlocale()
。 (由 Hugo van Kemenade 於 gh-111187 貢獻。)pathlib
:pathlib.PurePath.is_reserved()
已被棄用並計劃在 Python 3.15 中移除。從 Python 3.13 開始,請用os.path.isreserved
來偵測 Windows 上的保留路徑。platform
:java_ver()
已被棄用並將在 3.15 中移除。它幾乎沒有被測試過,API 令人困惑並且只對 Jython 支援有用。 (由 Nikita Sobolev 於 gh-116349 貢獻。)-
The check_home argument of
sysconfig.is_python_build()
has been deprecated since Python 3.12.
threading
:對threading.RLock()
傳遞任何引數現在已被棄用。C 版本允許任意數量的引數和關鍵字引數,但它們會被忽略。Python 版本不允許任何引數。所有引數將在 Python 3.15 中從threading.RLock()
中移除。 (由 Nikita Sobolev 於 gh-102029 貢獻。)-
用於建立
NamedTuple
類別的未以文件記錄之關鍵字引數語法 (NT = NamedTuple("NT", x=int)
) 已棄用,並將在 3.15 中被禁止。請改用基於類別的語法或函式語法 (functional syntax)。
-
types.CodeType
: Accessingco_lnotab
was deprecated in PEP 626 since 3.10 and was planned to be removed in 3.12, but it only got a properDeprecationWarning
in 3.12. May be removed in 3.15. (Contributed by Nikita Sobolev in gh-101866.)
-
當使用函式語法來建立
NamedTuple
類別時,沒將值傳遞給 fields 參數的方式 (NT = NamedTuple("NT")
) 已被棄用,將None
傳遞給 fields 參數(NT = NamedTuple("NT", None)
)也已被棄用。這兩者將在 Python 3.15 中會被禁止。要建立一個沒有欄位的NamedTuple
類別,請使用class NT(NamedTuple): pass
或NT = NamedTuple("NT", [])
。
typing.TypedDict
:當使用函式語法來建立TypedDict
類別時,沒將值傳遞給 fields 參數的方式(TD = TypedDict("TD")
)已被棄用,將None
傳遞給 fields 參數(TD = TypedDict("TD", None)
)也已被棄用。這兩者將在 Python 3.15 中會被禁止。要建立一個沒有欄位的TypedDict
類別,請使用class TD(TypedDict): pass
或TD = TypedDict("TD", {})
。wave
:已棄用wave.Wave_read
和wave.Wave_write
類別的getmark()
、setmark()
和getmarkers()
方法。它們將在 Python 3.15 中被移除。 (由 Victor Stinner 於 gh-105096 貢獻。)