Skip to content

gh-151575: Deprecate passing file paths instead of URLs to mimetypes.guess_type - #162708

Open
sirosen wants to merge 5 commits into
python:mainfrom
sirosen:guess-mimetype-deprecate-paths
Open

sirosen wants to merge 5 commits into
python:mainfrom
sirosen:guess-mimetype-deprecate-paths

Conversation

@sirosen

@sirosen sirosen commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

closes #151576

This is a continuation of the aforementioned PR.

Deprecate passing file paths (path objects or any string which urllib.parse doesn't see as having a scheme) to guess_type, slating removal of support for 3.21.
The soft-deprecation period, which started in 3.13 is noted in text under the deprecated-removed directive.

As part of this work, lazy imports are converted to the 3.15+ syntax and moved to the top of the file. And lazy imports which were not meaningfully lazy (sys, os, posixpath) were made non-lazy.


Are we satisfied with the test changes? I considered the following additional changes but decided to wait for feedback:

  • Move all of the deprecated usage tests to a new standalone test class
  • Add tests to confirm that file:// URLs do not trigger the warning

cc @StanFromIreland, @hugovk, I reviewed the original PR, and recall making a bit of a mistake with the way the deprecation should be stated. I'd especially appreciate your eyes on this one.

(Aside: I want to work through the deprecation process because there's an outstanding TODO I have on my list to go back to the devguide and document it. 😁 )

NaveenKumarG-dev and others added 4 commits November 26, 2026 17:37
…r file paths

feat: introduce MimeTypes class and deprecate file path support in guess_type with new guess_file_type method
feat: add guess_file_type to mimetypes module to support path-based MIME lookups
test: add test suite for mimetypes module
Address PR feedback: fix mimetypes CLI, lazy imports, and doc deprecations
os, sys, and posixpath are loaded on interpreter start -- making them
lazy has no meaningful effect, so they are made into plain imports.

urllib.parse, warnings, and argparse.ArgumentParser are made into lazy
imports.

Inline imports are removed.
Per discussion and feedback, passing a Path is noted in text (not with a
directive) as soft deprecated, and deprecated-removed for the 3.16 - 3.21
timeline.
@read-the-docs-community

read-the-docs-community Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants