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()
is deprecated and will be removed in Python 3.16; useinspect.iscoroutinefunction()
instead. (Contributed by Jiahao Li and Kumar Aditya in gh-122875.)asyncio
policy system is deprecated and will be removed in Python 3.16. In particular, the following classes and functions are deprecated:Users should use
asyncio.run()
orasyncio.Runner
with loop_factory to use the desired event loop implementation.For example, to use
asyncio.SelectorEventLoop
on Windows:import asyncio async def main(): ... asyncio.run(main(), loop_factory=asyncio.SelectorEventLoop)
(Contributed by Kumar Aditya in gh-127949.)
-
自 Python 3.12 起,布林型別的位元反轉
~True
或~False
已被棄用,因為它會產生不預期且不直觀的結果(-2
和-1
)。使用not x
代替布林值的邏輯否定。在極少數情況下,你需要對底層的整數進行位元反轉,請明確轉換為~int(x)
(~int(x)
)。
-
Calling the Python implementation of
functools.reduce()
with function or sequence as keyword arguments has been deprecated since Python 3.14.
-
Support for custom logging handlers with the strm argument is deprecated and scheduled for removal in Python 3.16. Define handlers with the stream argument instead. (Contributed by Mariusz Felisiak in gh-115032.)
-
Valid extensions start with a '.' or are empty for
mimetypes.MimeTypes.add_type()
. Undotted extensions are deprecated and will raise aValueError
in Python 3.16. (Contributed by Hugo van Kemenade in gh-75223.)
-
自 Python 3.14 起,
ExecError
例外已被棄用。自 Python 3.4 以來,它尚未被shutil
中的任何函式使用,現在是RuntimeError
的別名。
-
自 Python 3.14 起,
Class.get_methods
方法已被棄用。
sys
:自 Python 3.13 起,
_enablelegacywindowsfsencoding()
函式已被棄用。請改用PYTHONLEGACYWINDOWSFSENCODING
環境變數。
-
The
sysconfig.expand_makefile_vars()
function has been deprecated since Python 3.14. Use thevars
argument ofsysconfig.get_paths()
instead.
-
自 Python 3.13 起,未以文件記錄和未被使用的
TarFile.tarfile
屬性已被棄用。