计划在 Python 3.15 中移除

  • 导入系统:

    • 当设置 __spec__.cached 失败时在模块上设置 __cached__ 的做法已被弃用。 在 Python 3.15 中,__cached__ 将不会再被导入系统或标准库设置或纳入其考量。 (gh-97879)

    • 当设置 __spec__.parent 失败时在模块上设置 __package__ 的做法已被弃用。在 Python 3.15 中,__package__ 将不会再被导入系统或标准库纳入考虑。 (gh-97879)

  • ctypes:

    • 未写入文档的 ctypes.SetPointerType() 函数自 Python 3.13 起已被弃用。

  • http.server:

    • 过时且很少被使用的 CGIHTTPRequestHandler 自 Python 3.13 起已被弃用。 不存在直接的替代品。 对于建立带有请求处理器的 Web 服务器接口 任何东西 都比 CGI 强。

    • 用于 python -m http.server 命令行界面的 --cgi 旗标自 Python 3.13 起已被弃用。

  • importlib:

    • load_module() 方法:改用 exec_module()

  • pathlib:

    • .PurePath.is_reserved() 自 Python 3.13 起已被弃用。 请使用 os.path.isreserved() 来检测 Windows 上的保留路径。

  • platform:

    • platform.java_ver() 自 Python 3.13 起已被弃用。 此函数仅对 Jython 支持有用,具有令人困惑的 API,并且大部分未经测试。

  • sysconfig:

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

  • types:

    • types.CodeType: 访问 codeobject.co_lnotab 的做法自 3.10 起已根据 PEP 626 被弃用并曾计划在 3.12 中移除,但在 3.12 中仅设置了 DeprecationWarning。 可能会在 3.15 中移除。 (由 Nikita Sobolev 在 gh-101866 中贡献。)

  • typing:

    • 未写入文档的用于创建 NamedTuple 类的关键字参数语法 (例如 Point = NamedTuple("Point", x=int, y=int)) 自 Python 3.13 起已被弃用。请改用基于类的语法或函数式语法。

    • 当使用 TypedDict 的函数式语法时,不向 fields 形参传递值 (TD = TypedDict("TD")) 或传递 None (TD = TypedDict("TD", None)) 的做法自 Python 3.13 起已被弃用。请改用 class TD(TypedDict): passTD = TypedDict("TD", {}) 来创建一个零字段的 TypedDict。

    • typing.no_type_check_decorator() 装饰器自 Python 3.13 起已被弃用。 存在于 typing 模块八年之后,它仍未被任何主要类型检查器所支持。

  • sre_compile, sre_constantssre_parse 模块。

  • wave:

    • 自 Python 3.13 起 Wave_readWave_write 类的 getmark()setmark()getmarkers() 方法已被弃用。

  • zipimport:

    • zipimport.zipimporter.load_module() 自 Python 3.10 起已被弃用。 请改用 exec_module()。 (gh-125746。)