弃用
****


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

* "argparse": "argparse.BooleanOptionalAction" 的 *type*, *choices* 和
  *metavar* 形参已被弃用并将在 3.14 中移除。 （由 Nikita Sobolev 在
  gh-92248 中贡献。）

* "ast": 以下特性自 Python 3.8 起已在文档中声明弃用，现在当运行时如果
  它们被访问或使用时将发出 "DeprecationWarning"，并将在 Python 3.14 中
  移除：

  * "ast.Num"

  * "ast.Str"

  * "ast.Bytes"

  * "ast.NameConstant"

  * "ast.Ellipsis"

  请改用 "ast.Constant"。 （由 Serhiy Storchaka 在 gh-90953 中贡献。）

* "asyncio":

  * 子监视器类 "MultiLoopChildWatcher", "FastChildWatcher",
    "AbstractChildWatcher" 和 "SafeChildWatcher" 已被弃用并将在 Python
    3.14 中移除。 （由 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"。 用于类型标注时，则推荐并集运算符，如 "bytes | bytearray"
  ，或 "collections.abc.Buffer"。 （由 Shantanu Jain 在 gh-91896 中贡
  献。）

* "email": 已弃用 "email.utils.localtime()" 中的 *isdst* 形参。 （由
  Alan Williams 在 gh-72346 中贡献。）

* "importlib": "__package__" 和 "__cached__" 将不再被设置或是被导入系
  统纳入考量 (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" 具有对 copy, deepcopy 和 pickle 等操作的未写入文档的、低
  效的、历史上充满问题的且不稳定的支持。 这将在 3.14 中移除以显著减少
  代码量和维护负担。 （由 Raymond Hettinger 在 gh-101588 中贡献。）

* "multiprocessing": 默认的启动方法在目前默认使用 "'fork'" 的 Linux,
  BSD 和其他非 macOS POSIX 平台上将改为更安全的方法 (gh-84559)。 为此
  添加运行时警告将带来糟糕的体验因为大部分代码并不会关心这个问题。 当
  你的代码 *需要* "'fork'" 时请使用 "get_context()" 或
  "set_start_method()" API 来显式地指明。 参见 上下文和启动方法。

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

  * 如果使用了 命名占位符 且 *parameters* 是一个序列而不是 "dict" 则选
    择 "execute()" 和 "executemany()"。

  * date 和 datetime 适配器，date 和 timestamp 转换器：请参阅
    "sqlite3" 文档了解推荐的替代方案。

* "types.CodeType": 访问 "co_lnotab" 的做法自 3.10 起已在 **PEP 626**
  中被弃用并曾计划在 3.12 中移除，但实际上在 3.12 中仅设置了
  "DeprecationWarning"。 可能会在 3.14 中移除。 （由 Nikita Sobolev 在
  gh-101866 中贡献。）

* "typing": "ByteString" 自 Python 3.9 起已被弃用，现在当被使用时将会
  发出 "DeprecationWarning"。

* "urllib": "urllib.parse.Quoter" 已被弃用：它不应被作为公有 API。 （
  由 Gregory P. Smith 在 gh-88168 中贡献。）


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.

* "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.14 中移除
-------------------------

* "PyDictObject" 中的 "ma_version_tag" 字段用于扩展模块 ( **PEP 699**
  ; gh-101193 )。

* 创建 "immutable types"  的可变基础 ( 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" 副本。

* 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.
