python / python/cpython

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

Open
#151,575 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Lib/mimetypes.py at the existing TODO and inspect guess_type() alongside guess_file_type(). Verify the intended warning behavior for plain path strings, bytes, and os.PathLike inputs while preserving URL handling; the work is complete when the deprecation warning is covered and the existing behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.