未來版本中的待移除項目

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

  • argparse:已棄用巢狀引數群組和巢狀互斥群組。

  • array'u' 格式碼 (gh-57281)

  • builtins

    • bool(NotImplemented)

    • 產生器:throw(type, exc, tb)athrow(type, exc, tb) 簽名已被棄用:請改用 throw(exc)athrow(exc),為單引數簽名。

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

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

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

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

    • int() 委派給 __trunc__() 方法。

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

  • calendarcalendar.Januarycalendar.February 常數已被棄用並被 calendar.JANUARYcalendar.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

    • load_module() method:請改用 exec_module()

    • cache_from_source() debug_override 參數已被棄用:請改用 optimization 參數。

  • importlib.metadata

    • EntryPoints 元組介面。

    • 回傳值上的隱式 None

  • logging: the warn() method has been deprecated since Python 3.3, use warning() instead.

  • mailbox:已棄用 StringIO 輸入和文本模式,請改用 BytesIO 和二進位模式。

  • os:在多執行緒行程中呼叫 os.register_at_fork()

  • pydoc.ErrorDuringImportexc_info 參數的元組值已被棄用,請用例外實例。

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

  • sre_compilesre_constantssre_parse 模組。

  • shutilrmtree()onerror 參數在 Python 3.12 中已被棄用;請改用 onexc 參數。

  • ssl 選項和協定:

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

    • ssl.SSLContextset_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

  • sysconfig.is_python_build()check_home 參數已被棄用並被忽略。

  • threading 方法:

  • typing.Text (gh-92332)。

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

  • urllib.parse 已棄用函式:請改用 urlparse()

    • splitattr()

    • splithost()

    • splitnport()

    • splitpasswd()

    • splitport()

    • splitquery()

    • splittag()

    • splittype()

    • splituser()

    • splitvalue()

    • to_bytes()

  • urllib.request:呼叫請求的 URLopenerFancyURLopener 風格已被棄用。請改用更新的 urlopen() 函式和方法。

  • wsgirefSimpleHandler.stdout.write() 不應該進行部分寫入。

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

  • zipimport.zipimporter.load_module() 已被棄用:請改用 exec_module()