Python 3.16 中待移除的項目¶
引入系統 (import system):
在模組上設定
__loader__而沒有設定__spec__.loader的做法將於 Python 3.16 被棄用。在 Python 3.16 中,引入系統或標準函式庫將不再設定或考慮__loader__。
-
自 Python 3.3 起,
'u'格式碼 (wchar_t) 在文件中已被棄用,自 Python 3.13 起在 runtime 已被棄用。請使用'w'格式碼 (Py_UCS4) 來取代 Unicode 字元。
-
asyncio.iscoroutinefunction()已被棄用並將在 Python 3.16 中移除;請改用inspect.iscoroutinefunction()。(由 Jiahao Li 和 Kumar Aditya 於 gh-122875 貢獻。)asyncio策略系統已被棄用並將在 Python 3.16 中移除。特別是以下類別和函式已被棄用:使用者應該使用
asyncio.run()或asyncio.Runner搭配 loop_factory 來使用所需的事件迴圈實作。例如在 Windows 上使用
asyncio.SelectorEventLoop:import asyncio async def main(): ... asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
(由 Kumar Aditya 於 gh-127949 貢獻。)
-
自 Python 3.12 起,布林型別的位元反轉
~True或~False已被棄用,因為它會產生不預期且不直觀的結果(-2和-1)。使用not x代替布林值的邏輯否定。在極少數情況下,你需要對底層的整數進行位元反轉,請明確轉換為~int(x)(~int(x))。
-
自 Python 3.14 起,使用 function 或 sequence 關鍵字引數呼叫
functools.reduce()的 Python 實作已被棄用。
-
對具有 strm 引數的自訂日誌記錄處理函式的支援已被棄用,並計劃在 Python 3.16 中移除。請改用 stream 引數。(由 Mariusz Felisiak 於 gh-115032 貢獻。)
-
有效的副檔名以 '.' 開頭或對
mimetypes.MimeTypes.add_type()為空字串。未加點的副檔名已被棄用,並將在 Python 3.16 中引發ValueError。(由 Hugo van Kemenade 於 gh-75223 貢獻。)
-
自 Python 3.14 起,
ExecError例外已被棄用。自 Python 3.4 以來,它尚未被shutil中的任何函式使用,現在是RuntimeError的別名。
-
自 Python 3.14 起,
Class.get_methods方法已被棄用。
sys:自 Python 3.13 起,
_enablelegacywindowsfsencoding()函式已被棄用。請改用PYTHONLEGACYWINDOWSFSENCODING環境變數。
-
自 Python 3.14 起,
sysconfig.expand_makefile_vars()函式已被棄用。請改用sysconfig.get_paths()的vars引數。
-
自 Python 3.13 起,未以文件記錄和未被使用的
TarFile.tarfile屬性已被棄用。