python / python/cpython

Deprecate passing file paths instead of URLs to `mimetypes.guess_type()`

未关闭
#151,575 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Feature or enhancement

Proposal:

In Python 3.13, mimetypes.guess_file_type() was introduced as the preferred alternative to guess_type() for file paths. The documentation was updated with a .. soft-deprecated:: 3.13 note at the time.

However, the # TODO: Deprecate accepting file paths (in particular path-like objects) comment in Lib/mimetypes.py was never fulfilled, and no actual DeprecationWarning is currently emitted at runtime when paths are passed in.

This proposal is to fulfill the existing # TODO and emit a DeprecationWarning for passing plain strings (with no valid URL scheme), bytes, and os.PathLike objects into mimetypes.guess_type().

This completes the soft-deprecation cycle initiated in Python 3.13.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

This fulfills the existing # TODO added during the introduction of guess_file_type() in Python 3.13:
https://github.com/python/cpython/blob/main/Lib/mimetypes.py#L131

Linked PRs
  • gh-151576

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Lib/mimetypes.py 中现有的 TODO 开始,同时检查 guess_type() 和 guess_file_type()。在保留 URL 处理的同时,验证对普通路径字符串、bytes 和 os.PathLike 输入的预期警告行为;当弃用警告得到覆盖且现有行为仍然正确时,工作即告完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
backend-api-design
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
20/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。