GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-75223: Reject undotted extensions in `mimetypes.add_type()` by OddBloke · Pull Request #2895 · python/cpython

Conversation

@OddBloke

@OddBloke OddBloke commented Jul 26, 2017 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Extensions that don't start with a dot will never be found by
methods/functions that act on the registry, so we should stop users from
mistakenly adding them.

https://bugs.python.org/issue31040

  • Issue: mimetypes.add_type should complain when you give it an undotted ext #75223

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Jul 26, 2017
@OddBloke

OddBloke commented Jul 26, 2017

Copy link
Copy Markdown
Contributor Author

I've opened this now to get feedback on whether this is an appropriate change to make. Does it need a warning first, before it becomes the default behaviour?

(At a minimum, I would expect to need to add to documentation.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@brettcannon brettcannon added the awaiting review label Feb 2, 2018
@JulienPalard

JulienPalard commented Sep 10, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

As said in https://bugs.python.org/issue31040, please use startswith instead of find.

There is one case where it works without a dot:

>>> mimetypes.add_type('empty', '')
>>> mimetypes.guess_type('')
('empty', None)

And someone may have used it to distinguish between emptyness and type not found. What I propose:

Emit a warning in case the ext is empty, else ValueError in case the type does not start with a dot, to ensure we're not breaking any code.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JulienPalard
JulienPalard requested changes Sep 10, 2019
View reviewed changes
Comment thread Lib/mimetypes.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting changes and removed awaiting review labels Sep 10, 2019
@bedevere-bot

bedevere-bot commented Sep 10, 2019

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@OddBloke
OddBloke requested a review from a team as a code owner September 10, 2019 12:45
OddBloke added 2 commits September 10, 2019 09:33
@OddBloke
Add a test for mimetypes.add_type
2e6a0e5
@OddBloke
bpo-31040: Reject undotted extensions in mimetypes.add_type
1485be9
Extensions that don't start with a dot will never be found by
methods/functions that act on the registry, so we should stop users from
mistakenly adding them.

The one exception is the empty string extension.  This could be in use
to detect absent extensions, so instead of raising a ValueError we emit
a warning.
@OddBloke
OddBloke force-pushed the fix-for-31040 branch from b92d271 to 1485be9 Compare September 10, 2019 13:33
@OddBloke

OddBloke commented Sep 10, 2019

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting changes labels Sep 10, 2019
@bedevere-bot

bedevere-bot commented Sep 10, 2019

Copy link
Copy Markdown

Thanks for making the requested changes!

@JulienPalard: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot
bedevere-bot requested a review from JulienPalard September 10, 2019 13:53
JulienPalard
JulienPalard previously requested changes Sep 13, 2019
View reviewed changes
Comment thread Lib/mimetypes.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Sep 13, 2019

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting changes and removed awaiting change review labels Sep 13, 2019
@github-actions

This comment was marked as outdated.

Sign in to view
@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 20, 2022
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jul 29, 2022
@github-actions

This comment was marked as outdated.

Sign in to view
@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Aug 30, 2022
@arhadthedev arhadthedev changed the title bpo-31040: Reject undotted extensions in mimetypes.add_type gh-75223: Reject undotted extensions in mimetypes.add_type Apr 15, 2023
@arhadthedev arhadthedev added topic-email stdlib Standard Library Python modules in the Lib/ directory labels Apr 15, 2023
@hugovk hugovk mentioned this pull request Nov 21, 2024
Add dot to extensions of added MIME types astropy/pyvo#622
Merged
@OddBloke OddBloke mannequin mentioned this pull request Apr 10, 2022
mimetypes.add_type should complain when you give it an undotted ext #75223
Closed
@github-actions

This comment was marked as outdated.

Sign in to view
@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Dec 21, 2024
@encukou

encukou commented Jan 3, 2025

Copy link
Copy Markdown
Member

IMO, this is a backwards-incompatible change and should be deprecated with a warning, and documented. (For example, if add_type is fed from a data file, this PR can change a relatively harmless data-entry error into a hard failure. Or someone could use types_map directly.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the stale Stale PR or inactive for long period of time. label Jan 3, 2025
@hugovk hugovk mentioned this pull request Jan 8, 2025
gh-75223: Deprecate undotted extensions in mimetypes.MimeTypes.add_type #128638
Merged
@hugovk
hugovk marked this pull request as draft January 8, 2025 15:12
@hugovk

hugovk commented Jan 8, 2025

Copy link
Copy Markdown
Member

Thanks, please see #128638 to deprecate it first, and I've marked this as a draft until it's ready for merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

This comment was marked as outdated.

Sign in to view
@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Feb 7, 2025
@StanFromIreland
Merge branch 'main' into fix-for-31040
b34278f
@StanFromIreland StanFromIreland removed the stale Stale PR or inactive for long period of time. label May 9, 2026
@StanFromIreland

StanFromIreland commented May 9, 2026

Copy link
Copy Markdown
Member

Thanks, please see #128638 to deprecate it first, and I've marked this as a draft until it's ready for merge.

It was deprecated and scheduled for 3.16, so it's time!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland StanFromIreland self-assigned this May 9, 2026
StanFromIreland added 2 commits May 9, 2026 18:56
@StanFromIreland
Remove duplicate after merge, add to What's New and tidy up
c1b6fec
@StanFromIreland
!fixup leftover line
c491311
@read-the-docs-community

read-the-docs-community Bot commented May 9, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32618039 | 📁 Comparing c491311 against main (7241f27)

  🔍 Preview build  

3 files changed
± library/mimetypes.html
± whatsnew/3.16.html
± whatsnew/changelog.html
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland
StanFromIreland marked this pull request as ready for review May 9, 2026 18:09
@StanFromIreland
StanFromIreland requested a review from AA-Turner as a code owner May 9, 2026 18:09
@bedevere-app bedevere-app Bot added the awaiting review label May 9, 2026
@StanFromIreland
StanFromIreland requested review from JulienPalard and hugovk May 9, 2026 18:09
@StanFromIreland StanFromIreland changed the title gh-75223: Reject undotted extensions in mimetypes.add_type gh-75223: Reject undotted extensions in mimetypes.add_type() May 9, 2026
@StanFromIreland StanFromIreland removed their assignment May 9, 2026
StanFromIreland
StanFromIreland reviewed May 9, 2026
View reviewed changes
Comment thread Doc/library/mimetypes.rst

.. function:: add_type(type, ext, strict=True)

Add a mapping from the MIME type *type* to the extension *ext*. When the

@StanFromIreland StanFromIreland May 9, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have the same "Valid extensions start with a '.' or are empty." note IMO, but it wasn't updated before?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@StanFromIreland

StanFromIreland commented May 12, 2026

Copy link
Copy Markdown
Member

Completed in #149721.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland StanFromIreland closed this May 12, 2026
@github-project-automation github-project-automation Bot moved this from Waiting Done to Done in CPython pull requests to have finally merged May 12, 2026
@StanFromIreland StanFromIreland mentioned this pull request May 12, 2026
gh-149720: Remove support for undotted ext in mimetypes.MimeType.add_type #149721
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@StanFromIreland StanFromIreland StanFromIreland left review comments
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@hugovk hugovk Awaiting requested review from hugovk
@JulienPalard JulienPalard Awaiting requested review from JulienPalard

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review stdlib Standard Library Python modules in the Lib/ directory topic-email

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@OddBloke @JulienPalard @bedevere-bot @encukou @hugovk @StanFromIreland @brettcannon @arhadthedev @the-knights-who-say-ni @ezio-melotti
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.