計劃在 Python 3.16 中移除¶
匯入系統
在模組上設定
__loader__
而不設定__spec__.loader
已被棄用。在 Python 3.16 中,匯入系統或標準庫將不再設定或考慮__loader__
。
-
自 Python 3.3 起,文件中已棄用
'u'
格式程式碼(wchar_t
),自 Python 3.13 起在執行時已棄用。請改用'w'
格式程式碼(Py_UCS4
)表示 Unicode 字元。
-
asyncio.iscoroutinefunction()
已被棄用,將在 Python 3.16 中移除,請改用inspect.iscoroutinefunction()
。(由 Jiahao Li 和 Kumar Aditya 在 gh-122875 中貢獻。)
-
自 Python 3.12 起,布林型別上的按位取反
~True
或~False
已被棄用,因為它會產生令人驚訝且不直觀的結果(-2
和-1
)。請改用not x
來表示布林值的邏輯否定。在極少數情況下,您需要底層整數的按位取反,請顯式轉換為int
(~int(x)
)。
-
自 Python 3.14 起,
ExecError
異常已被棄用。shutil
中的任何函式自 Python 3.4 起都未使用它,現在它是RuntimeError
的別名。
-
自 Python 3.14 起,
Class.get_methods
方法已被棄用。
sys
:自 Python 3.13 起,
_enablelegacywindowsfsencoding()
函式已被棄用。請改用PYTHONLEGACYWINDOWSFSENCODING
環境變數。
-
自 Python 3.13 起,未記錄且未使用的
TarFile.tarfile
屬性已被棄用。