已棄用項目
**********


Python 3.13 中待移除的項目
==========================

模組（請見 **PEP 594**）：

* "aifc"

* "audioop"

* "cgi"

* "cgitb"

* "chunk"

* "crypt"

* "imghdr"

* "mailcap"

* "msilib"

* "nis"

* "nntplib"

* "ossaudiodev"

* "pipes"

* "sndhdr"

* "spwd"

* "sunau"

* "telnetlib"

* "uu"

* "xdrlib"

其他模組：

* "lib2to3" 和 **2to3** 程式 (gh-84540)

API：

* "configparser.LegacyInterpolation" (gh-90765)

* "locale.resetlocale()" (gh-90817)

* "turtle.RawTurtle.settiltangle()" (gh-50096)

* "unittest.findTestCases()" (gh-50096)

* "unittest.getTestCaseNames()" (gh-50096)

* "unittest.makeSuite()" (gh-50096)

* "unittest.TestProgram.usageExit()" (gh-67048)

* "webbrowser.MacOSX" (gh-86421)

* "classmethod" 描述器鏈接 (gh-89519)

* "importlib.resources" 的已棄用方法：

  * "contents()"

  * "is_resource()"

  * "open_binary()"

  * "open_text()"

  * "path()"

  * "read_binary()"

  * "read_text()"

  請改用 "importlib.resources.files()"。請參閱 importlib-resources:
  Migrating from Legacy (gh-106531)


Python 3.14 中待移除的項目
==========================

* "argparse"："argparse.BooleanOptionalAction" 的 *type*、*choices* 和
  *metavar* 參數已被棄用，將在 3.14 中移除。 (由 Nikita Sobolev 於
  gh-92248 貢獻。)

* "ast"：自 Python 3.8 起，下列功能已在文件中被棄用，現在在存取或使用
  時會於 runtime 發出 "DeprecationWarning"，並將在 Python 3.14 中移除
  ：

  * "ast.Num"

  * "ast.Str"

  * "ast.Bytes"

  * "ast.NameConstant"

  * "ast.Ellipsis"

  請改用 "ast.Constant"。（由 Serhiy Storchaka 於 gh-90953 貢獻。）

* "asyncio"：

  * 已棄用並將在 Python 3.14 中移除的 child watcher 類別：
    "MultiLoopChildWatcher"、"FastChildWatcher"、
    "AbstractChildWatcher" 和 "SafeChildWatcher"。 (由 Kumar Aditya 於
    gh-94597 貢獻。)

  * "asyncio.set_child_watcher()"、"asyncio.get_child_watcher()"、
    "asyncio.AbstractEventLoopPolicy.set_child_watcher()" 和
    "asyncio.AbstractEventLoopPolicy.get_child_watcher()" 已被棄用並將
    在 Python 3.14 中移除。（由 Kumar Aditya 於 gh-94597 貢獻。）

  * 預設事件迴圈策略的 "get_event_loop()" 方法現在會在沒有設定目前事件
    迴圈且決定建立一個時發出 "DeprecationWarning"。 (由 Serhiy
    Storchaka 和 Guido van Rossum 於 gh-100160 貢獻。)

* "collections.abc"：已棄用 "ByteString"。請改用 "Sequence" 或
  "Buffer"。在 typing 中使用時，請改用聯集，如 "bytes | bytearray"，或
  "collections.abc.Buffer"。（由 Shantanu Jain 於 gh-91896 貢獻。）

* "email"：已棄用 "email.utils.localtime()" 中的 *isdst* 參數。（由
  Alan Williams 於 gh-72346 貢獻。）

* "importlib"："__package__" 和 "__cached__" 將不再被設定或被 import
  系統考慮。 (gh-97879)

* "importlib.abc" 的已棄用類別：

  * "importlib.abc.ResourceReader"

  * "importlib.abc.Traversable"

  * "importlib.abc.TraversableResources"

  請改用 "importlib.resources.abc" 類別：

  * "importlib.resources.abc.Traversable"

  * "importlib.resources.abc.TraversableResources"

  （由 Jason R. Coombs 和 Hugo van Kemenade 貢獻於 gh-93963。）

* "itertools" 有不以文件記錄、效率低下、過去常有 bug 且不一致的 copy、
  deepcopy 和 pickle 操作支援。將在 3.14 中移除以大幅減少程式碼量和維
  護負擔。 (由 Raymond Hettinger 於 gh-101588 貢獻。)

* "multiprocessing"：預設的啟動方法將在 Linux、BSD 和其他非 macOS
  POSIX 平台上更改為更安全的 方法，目前 "'fork'" 是預設值 (gh-84559)。
  對此增加一個 runtime 警告被認為太過擾人，因為 大多數程式碼不會在意。
  請使用 "get_context()" 或 "set_start_method()" API 來明確指定你的程
  式碼何時*需要* "'fork'"。請參閱 Contexts and start methods。

* "pathlib"：已棄用 "is_relative_to()" 和 "relative_to()"：額外引數的
  傳遞已被棄用。

* "pkgutil"："find_loader()" 和 "get_loader()" 現在會引發
  "DeprecationWarning"；請改用 "importlib.util.find_spec()"。 (由
  Nikita Sobolev 於 gh-97850 貢獻。)

* "pty"：

  * "master_open()"：請用 "pty.openpty()"。

  * "slave_open()"：請用 "pty.openpty()"。

* "sqlite3"：

  * "version" 和 "version_info"。

  * "execute()" 和 "executemany()"，如果使用 named placeholders 且
    *parameters* 是序列而不是 "dict"。

* "typing"：自 Python 3.9 起已被棄用的 "ByteString" 現在在使用時會發出
  "DeprecationWarning"。

* "urllib"："urllib.parse.Quoter" 已被棄用：它並非預期的公開 API。(由
  Gregory P. Smith 於 gh-88168 貢獻。)


Python 3.15 中待移除的項目
==========================

* "http.server.CGIHTTPRequestHandler" 將會被移除，連同其相關的 "--cgi"
  旗標到 "python -m http.server"。它已經過時且很少被使用。沒有直接的替
  代方案。*任何東西*都比 CGI 更好的來介接一個帶有請求處理器的網頁伺服
  器。

* "importlib"：

  * "load_module()" method：請改用 "exec_module()"。

* "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 貢獻。)

* "sysconfig":

  * 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 貢獻。)

* "typing.NamedTuple"：

  * 用於建立 "NamedTuple" 類別的未以文件記錄之關鍵字引數語法 ("NT =
    NamedTuple("NT", x=int)") 已棄用，並將在 3.15 中被禁止。請改用基於
    類別的語法或函式語法 (functional syntax)。

* "types":

  * "types.CodeType": Accessing "co_lnotab" was deprecated in **PEP
    626** since 3.10 and was planned to be removed in 3.12, but it
    only got a proper "DeprecationWarning" in 3.12. May be removed in
    3.15. (Contributed by Nikita Sobolev in gh-101866.)

* "typing":

  * 當使用函式語法來建立 "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 貢獻。)


Python 3.16 中待移除的項目
==========================

* The import system:

  * Setting "__loader__" on a module while failing to set
    "__spec__.loader" is deprecated. In Python 3.16, "__loader__" will
    cease to be set or taken into consideration by the import system
    or the standard library.

* "array"："array.array" "'u'" 型別 ("wchar_t")：請改用 "'w'" 型別
  ("Py_UCS4")。

* "builtins"："~bool"，對 bool 進行位元反轉。

* "symtable"：由於並沒有太多關注，已棄用
  "symtable.Class.get_methods()"。 (由 Bénédikt Tran 於 gh-119698 貢獻
  。)


未來版本中的待移除項目
======================

以下 API 將在未來被移除，雖然目前尚未安排移除日期。

* "argparse"：已棄用巢狀引數群組和巢狀互斥群組。

* "array" 的 "'u'" 格式碼 (gh-57281)

* "builtins"：

  * "bool(NotImplemented)"。

  * 產生器："throw(type, exc, tb)" 和 "athrow(type, exc, tb)" 簽名已被
    棄用：請改用 "throw(exc)" 和 "athrow(exc)"，為單引數簽名。

  * 目前 Python 接受數值字面值後面立即接關鍵字，例如 "0in x"、"1or x"
    、"0if 1else 2"。它讓表達式模糊且容易混淆，如 "[0x1for x in y]"（
    可以解釋為 "[0x1 for x in y]" 或 "[0x1f or x in y]"）。如果數值字
    面值後立即接 "and"、"else"、"for"、"if"、"in"、"is" 和 "or" 之一的
    關鍵字，則會引發語法警告。在未來版本中，它將被更改為語法錯誤。
    (gh-87999)

  * "__index__()" 和 "__int__()" 方法回傳非 int 型別的支援：這些方法將
    需要回傳 "int" 的嚴格子類別實例。

  * 回傳 "float" 嚴格子類別 "__float__()" 方法的支援：這些方法將需要回
    傳 "float" 的實例。

  * 回傳 "complex" 嚴格子類別 "__complex__()" 方法的支援：這些方法將需
    要回傳 "complex" 的實例。

  * 將 "int()" 委派給 "__trunc__()" 方法。

  * 在 "complex()" 建構子中將複數作為 *real* 或 *imag* 引數傳遞現在已
    被棄用；它應該只作為單個位置引數傳遞。 (由 Serhiy Storchaka 於
    gh-109218 貢獻。)

* "calendar"："calendar.January" 和 "calendar.February" 常數已被棄用並
  被 "calendar.JANUARY" 和 "calendar.FEBRUARY" 取代。 (由 Prince
  Roshan 於 gh-103636 貢獻。)

* "codeobject.co_lnotab"：請改用 "codeobject.co_lines()" 方法。

* "datetime"：

  * "utcnow()"：請改用 "datetime.datetime.now(tz=datetime.UTC)"。

  * "utcfromtimestamp()"：請改用
    "datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC)"。

* "gettext"：複數值必須是整數。

* "importlib"：

  * "cache_from_source()" *debug_override* 參數已被棄用：請改用
    *optimization* 參數。

* "importlib.metadata"：

  * "EntryPoints" 元組介面。

  * 回傳值上的隱式 "None"。

* "mailbox"：已棄用 StringIO 輸入和文本模式，請改用 BytesIO 和二進位模
  式。

* "os"：在多執行緒行程中呼叫 "os.register_at_fork()"。

* "pydoc.ErrorDuringImport"：*exc_info* 參數的元組值已被棄用，請用例外
  實例。

* "re"：現在對正規表示式中的數值群組參照和群組名稱用了更嚴格的規則。現
  在只有 ASCII 數碼序列被接受作為數值參照。位元組模式和替換字串中的群
  組名稱現在只能包含 ASCII 字母、數碼和底線。（由 Serhiy Storchaka 於
  gh-91760 貢獻。）

* "sre_compile"、"sre_constants" 和 "sre_parse" 模組。

* "shutil"："rmtree()" 的 *onerror* 參數在 Python 3.12 中已被棄用；請
  改用 *onexc* 參數。

* "ssl" 選項和協定：

  * 不帶協定引數的 "ssl.SSLContext" 已被棄用。

  * "ssl.SSLContext"："set_npn_protocols()" 和
    "selected_npn_protocol()" 已被棄用：請改用 ALPN。

  * "ssl.OP_NO_SSL*" 選項

  * "ssl.OP_NO_TLS*" 選項

  * "ssl.PROTOCOL_SSLv3"

  * "ssl.PROTOCOL_TLS"

  * "ssl.PROTOCOL_TLSv1"

  * "ssl.PROTOCOL_TLSv1_1"

  * "ssl.PROTOCOL_TLSv1_2"

  * "ssl.TLSVersion.SSLv3"

  * "ssl.TLSVersion.TLSv1"

  * "ssl.TLSVersion.TLSv1_1"

* "threading" 方法：

  * "threading.Condition.notifyAll()"：請用 "notify_all()"。

  * "threading.Event.isSet()"：請用 "is_set()"。

  * "threading.Thread.isDaemon()"、"threading.Thread.setDaemon()"：請
    用 "threading.Thread.daemon" 屬性。

  * "threading.Thread.getName()"、"threading.Thread.setName()"：請用
    "threading.Thread.name" 屬性。

  * "threading.currentThread()"：請用 "threading.current_thread()"。

  * "threading.activeCount()"：請用 "threading.active_count()"。

* "typing.Text" (gh-92332)。

* "unittest.IsolatedAsyncioTestCase"：從測試案例中回傳非 "None" 的值已
  被棄用。

* "urllib.parse" 已棄用函式：請改用 "urlparse()"。

  * "splitattr()"

  * "splithost()"

  * "splitnport()"

  * "splitpasswd()"

  * "splitport()"

  * "splitquery()"

  * "splittag()"

  * "splittype()"

  * "splituser()"

  * "splitvalue()"

  * "to_bytes()"

* "urllib.request"：呼叫請求的 "URLopener" 和 "FancyURLopener" 風格已
  被棄用。請改用更新的 "urlopen()" 函式和方法。

* "wsgiref"："SimpleHandler.stdout.write()" 不應該進行部分寫入。

* "xml.etree.ElementTree"：已棄用對 "Element" 的真值測試。在未來版本中
  ，它將始終回傳 "True"。請改用明確的 "len(elem)" 或 "elem is not
  None" 測試。

* "zipimport.zipimporter.load_module()" 已被棄用：請改用
  "exec_module()"。


C API 的棄用項目
================


Python 3.14 中待移除的項目
--------------------------

* "PyDictObject" 中的 "ma_version_tag" 欄位，用於擴充模組 (**PEP 699**
  ；gh-101193)。

* 使用可變基底建立"不可變型別" (gh-95388)。

* 設定 Python 初始化的函式，Python 3.11 中已被棄用：

  * "PySys_SetArgvEx()": Set "PyConfig.argv" instead.

  * "PySys_SetArgv()": Set "PyConfig.argv" instead.

  * "Py_SetProgramName()": Set "PyConfig.program_name" instead.

  * "Py_SetPythonHome()": Set "PyConfig.home" instead.

  "Py_InitializeFromConfig()" API 應該與 "PyConfig" 一起使用。

* 全域設定變數：

  * "Py_DebugFlag": Use "PyConfig.parser_debug" instead.

  * "Py_VerboseFlag": Use "PyConfig.verbose" instead.

  * "Py_QuietFlag": Use "PyConfig.quiet" instead.

  * "Py_InteractiveFlag": Use "PyConfig.interactive" instead.

  * "Py_InspectFlag": Use "PyConfig.inspect" instead.

  * "Py_OptimizeFlag": Use "PyConfig.optimization_level" instead.

  * "Py_NoSiteFlag": Use "PyConfig.site_import" instead.

  * "Py_BytesWarningFlag": Use "PyConfig.bytes_warning" instead.

  * "Py_FrozenFlag": Use "PyConfig.pathconfig_warnings" instead.

  * "Py_IgnoreEnvironmentFlag": Use "PyConfig.use_environment"
    instead.

  * "Py_DontWriteBytecodeFlag": Use "PyConfig.write_bytecode" instead.

  * "Py_NoUserSiteDirectory": Use "PyConfig.user_site_directory"
    instead.

  * "Py_UnbufferedStdioFlag": Use "PyConfig.buffered_stdio" instead.

  * "Py_HashRandomizationFlag": Use "PyConfig.use_hash_seed" and
    "PyConfig.hash_seed" instead.

  * "Py_IsolatedFlag": Use "PyConfig.isolated" instead.

  * "Py_LegacyWindowsFSEncodingFlag": Use
    "PyPreConfig.legacy_windows_fs_encoding" instead.

  * "Py_LegacyWindowsStdioFlag": Use "PyConfig.legacy_windows_stdio"
    instead.

  * "Py_FileSystemDefaultEncoding": Use "PyConfig.filesystem_encoding"
    instead.

  * "Py_HasFileSystemDefaultEncoding": Use
    "PyConfig.filesystem_encoding" instead.

  * "Py_FileSystemDefaultEncodeErrors": Use
    "PyConfig.filesystem_errors" instead.

  * "Py_UTF8Mode": Use "PyPreConfig.utf8_mode" instead. (see
    "Py_PreInitialize()")

  "Py_InitializeFromConfig()" API 應該與 "PyConfig" 一起使用。


Python 3.15 中待移除的項目
--------------------------

* "libmpdecimal" 的打包副本 (bundled copy)。

* The "PyImport_ImportModuleNoBlock()": Use "PyImport_ImportModule()"
  instead.

* "PyWeakref_GetObject()" and "PyWeakref_GET_OBJECT()": Use
  "PyWeakref_GetRef()" instead.

* "Py_UNICODE" type and the "Py_UNICODE_WIDE" macro: Use "wchar_t"
  instead.

* Python 初始化函式：

  * "PySys_ResetWarnOptions()": Clear "sys.warnoptions" and
    "warnings.filters" instead.

  * "Py_GetExecPrefix()": Get "sys.exec_prefix" instead.

  * "Py_GetPath()": Get "sys.path" instead.

  * "Py_GetPrefix()": Get "sys.prefix" instead.

  * "Py_GetProgramFullPath()": Get "sys.executable" instead.

  * "Py_GetProgramName()": Get "sys.executable" instead.

  * "Py_GetPythonHome()": Get "PyConfig.home" or the "PYTHONHOME"
    environment variable instead.


未來版本中的待移除項目
----------------------

下列 API 已被棄用並將會被移除，不過目前尚未訂定移除日期。

* "Py_TPFLAGS_HAVE_FINALIZE": Unneeded since Python 3.8.

* "PyErr_Fetch()": Use "PyErr_GetRaisedException()" instead.

* "PyErr_NormalizeException()": Use "PyErr_GetRaisedException()"
  instead.

* "PyErr_Restore()": Use "PyErr_SetRaisedException()" instead.

* "PyModule_GetFilename()": Use "PyModule_GetFilenameObject()"
  instead.

* "PyOS_AfterFork()": Use "PyOS_AfterFork_Child()" instead.

* "PySlice_GetIndicesEx()": Use "PySlice_Unpack()" and
  "PySlice_AdjustIndices()" instead.

* "PyUnicode_AsDecodedObject()": Use "PyCodec_Decode()" instead.

* "PyUnicode_AsDecodedUnicode()": Use "PyCodec_Decode()" instead.

* "PyUnicode_AsEncodedObject()": Use "PyCodec_Encode()" instead.

* "PyUnicode_AsEncodedUnicode()": Use "PyCodec_Encode()" instead.

* "PyUnicode_READY()": Unneeded since Python 3.12

* "PyErr_Display()": Use "PyErr_DisplayException()" instead.

* "_PyErr_ChainExceptions()": Use "_PyErr_ChainExceptions1()" instead.

* "PyBytesObject.ob_shash" 成員：請改為呼叫 "PyObject_Hash()"。

* "PyDictObject.ma_version_tag" 成員。

* 執行緒局部儲存 (Thread Local Storage, TLS) API：

  * "PyThread_create_key()": Use "PyThread_tss_alloc()" instead.

  * "PyThread_delete_key()": Use "PyThread_tss_free()" instead.

  * "PyThread_set_key_value()": Use "PyThread_tss_set()" instead.

  * "PyThread_get_key_value()": Use "PyThread_tss_get()" instead.

  * "PyThread_delete_key_value()": Use "PyThread_tss_delete()"
    instead.

  * "PyThread_ReInitTLS()": Unneeded since Python 3.7.
