未來版本中的待移除項目¶
以下 API 將在未來被移除,雖然目前尚未安排移除日期。
argparse
:已棄用巢狀引數群組和巢狀互斥群組。-
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
的嚴格子類別實例。將
int()
委派給__trunc__()
方法。在
complex()
建構子中將複數作為 real 或 imag 引數傳遞現在已被棄用;它應該只作為單個位置引數傳遞。 (由 Serhiy Storchaka 於 gh-109218 貢獻。)
calendar
:calendar.January
和calendar.February
常數已被棄用並被calendar.JANUARY
和calendar.FEBRUARY
取代。 (由 Prince Roshan 於 gh-103636 貢獻。)-
utcnow()
:請改用datetime.datetime.now(tz=datetime.UTC)
。utcfromtimestamp()
:請改用datetime.datetime.fromtimestamp(timestamp, tz=datetime.UTC)
。
gettext
:複數值必須是整數。-
load_module()
method:請改用exec_module()
。cache_from_source()
debug_override 參數已被棄用:請改用 optimization 參數。
-
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
sysconfig.is_python_build()
的 check_home 參數已被棄用並被忽略。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()
。
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
測試。