弃用
****


Python 3.15 中的待移除功能
==========================

* "ctypes":

  * The undocumented "ctypes.SetPointerType()" function has been
    deprecated since Python 3.13.

* "http.server":

  * The obsolete and rarely used "CGIHTTPRequestHandler" has been
    deprecated since Python 3.13. No direct replacement exists.
    *Anything* is better than CGI to interface a web server with a
    request handler.

  * The "--cgi" flag to the **python -m http.server** command-line
    interface has been deprecated since Python 3.13.

* "importlib": "__package__" 和 "__cached__" 将不再被设置或是被导入系
  统纳入考量 (gh-97879)。

* "locale":

  * The "getdefaultlocale()" function has been deprecated since Python
    3.11. Its removal was originally planned for Python 3.13
    (gh-90817), but has been postponed to Python 3.15. Use
    "getlocale()", "setlocale()", and "getencoding()" instead.
    (Contributed by Hugo van Kemenade in gh-111187.)

* "pathlib":

  * "PurePath.is_reserved()" has been deprecated since Python 3.13.
    Use "os.path.isreserved()" to detect reserved paths on Windows.

* "platform":

  * "java_ver()" has been deprecated since Python 3.13. This function
    is only useful for Jython support, has a confusing API, and is
    largely untested.

* "threading":

  * "RLock()" will take no arguments in Python 3.15. Passing any
    arguments has been deprecated since Python 3.14, as the  Python
    version does not permit any arguments, but the C version allows
    any number of positional or keyword arguments, ignoring every
    argument.

* "typing":

  * The undocumented keyword argument syntax for creating "NamedTuple"
    classes (e.g. "Point = NamedTuple("Point", x=int, y=int)") has
    been deprecated since Python 3.13. Use the class-based syntax or
    the functional syntax instead.

  * The "typing.no_type_check_decorator()" decorator function has been
    deprecated since Python 3.13. After eight years in the "typing"
    module, it has yet to be supported by any major type checker.

* "wave":

  * The "getmark()", "setmark()", and "getmarkers()" methods of the
    "Wave_read" and "Wave_write" classes have been deprecated since
    Python 3.13.


计划在 Python 3.16 中移除
=========================

* "builtins":

  * Bitwise inversion on boolean types, "~True" or "~False" has been
    deprecated since Python 3.12, as it produces surprising and
    unintuitive results ("-2" and "-1"). Use "not x" instead for the
    logical negation of a Boolean. In the rare case that you need the
    bitwise inversion of the underlying integer, convert to "int"
    explicitly ("~int(x)").

* "array":

  * The "'u'" format code ("wchar_t") has been deprecated in
    documentation since Python 3.3 and at runtime since Python 3.13.
    Use the "'w'" format code ("Py_UCS4") for Unicode characters
    instead.

* "shutil":

  * The "ExecError" exception has been deprecated since Python 3.14.
    It has not been used by any function in "shutil" since Python 3.4,
    and is now an alias of "RuntimeError".

* "symtable":

  * The "Class.get_methods" method has been deprecated since Python
    3.14.

* "sys":

  * The "_enablelegacywindowsfsencoding()" function has been
    deprecated since Python 3.13. Use the
    "PYTHONLEGACYWINDOWSFSENCODING" environment variable instead.

* "tarfile":

  * The undocumented and unused "TarFile.tarfile" attribute has been
    deprecated since Python 3.13.


计划在未来版本中移除
====================

以下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":

  * "load_module()" 方法：改用 "exec_module()"。

  * "cache_from_source()" *debug_override* 形参已被弃用：改用
    *optimization* 形参。

* "importlib.metadata":

  * "EntryPoints" 元组接口。

  * 返回值中隐式的 "None"。

* "logging": "warn()" 方法自 Python 3.3 起已被弃用，请改用 "warning()"
  。

* "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" 不带 protocol 参数的做法已被弃用。

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

* "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.15 中的待移除功能
--------------------------

* 捆绑的 "libmpdecimal" 副本。

* 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" 成员。

* 线程本地存储 (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.
