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 — mimetypes.add_type should complain when you give it an undotted ext · Issue #75223 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed as duplicate
Closed as duplicate
mimetypes.add_type should complain when you give it an undotted ext#75223
Copy link
Labels
3.7 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

Description

OddBloke
mannequin
opened on Jul 25, 2017
Issue body actions
BPO 31040
Nosy @OddBloke, @JimJJewett, @JulienPalard, @rcj4747
PRs
  • bpo-31040: Add warning note about mimetypes.add_type ext argument format #2871
  • gh-75223: Reject undotted extensions in mimetypes.add_type() #2895
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-07-25.19:25:41.891>
    labels = ['3.7', 'library', 'docs']
    title = 'mimetypes.add_type should complain when you give it an undotted ext'
    updated_at = <Date 2019-09-13.10:59:42.020>
    user = 'https://github.com/OddBloke'

    bugs.python.org fields:

    activity = <Date 2019-09-13.10:59:42.020>
    actor = 'mdk'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2017-07-25.19:25:41.891>
    creator = 'odd_bloke'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31040
    keywords = []
    message_count = 4.0
    messages = ['299135', '306501', '352266', '352286']
    nosy_count = 5.0
    nosy_names = ['odd_bloke', 'docs@python', 'Jim.Jewett', 'mdk', 'rcj']
    pr_nums = ['2871', '2895']
    priority = 'normal'
    resolution = None
    stage = 'commit review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue31040'
    versions = ['Python 3.7']

    Linked PRs

    • gh-75223: Reject undotted extensions in mimetypes.add_type() #2895
    • gh-75223: Deprecate undotted extensions in mimetypes.MimeTypes.add_type #128638

    Activity

    1. OddBloke commented on Jul 25, 2017

      @OddBloke
      OddBlokemannequin
      on Jul 25, 2017
      MannequinAuthor
      More actions
      import mimetypes
      
      print(mimetypes.guess_type('foo.manifest'))
      mimetypes.add_type('text/plain', 'manifest')
      print(mimetypes.guess_type('foo.manifest'))

      results in:

      ('application/x-ms-manifest', None)
      ('application/x-ms-manifest', None)

      I (mistakenly) expected the latter print to give me "('text/plain', None)". It doesn't because I should have prepended a . to the second add_type argument.

      I think add_type should error out when given an extension without a dot-prefix, because it's extremely unlikely that code that does so is behaving as intended with the current implementation.

      (At the very least, documentation should be updated to make this expectation clearer.)

    2. OddBloke
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Jul 25, 2017
    3. Mariatta
      added
      docsDocumentation in the Doc dirDocumentation in the Doc dir
      3.7 (EOL)end of lifeend of life
      on Jul 26, 2017
    4. Mariatta
      assigned
      docspython
      on Jul 26, 2017
    5. jimjjewett commented on Nov 19, 2017

      @jimjjewett
      jimjjewettmannequin
      on Nov 19, 2017
      Mannequin
      More actions

      Ideally, use .startswith('.') Instead if find, but this is a clear UI fix. First pull request fixes doc, second fixes code. OK to apply both.

    6. JulienPalard commented on Sep 13, 2019

      @JulienPalard
      JulienPalard
      on Sep 13, 2019
      Member
      More actions

      I think we should deprecate calling add_type with an empty ext, as I don't think it's a feature, more a side effect of the current implementation.

      But as some may use it like a feature, I asked the current PR to emit a warning, to not break the current implementations.

      To be able to simplify in the future, why not deprecating empty ext so we can remove it in a few versions?

    7. JulienPalard commented on Sep 13, 2019

      @JulienPalard
      JulienPalard
      on Sep 13, 2019
      Member
      More actions

      I just found a case where the empty mime type is actually usefull, it's in Lib/http/server.py:

          extensions_map = mimetypes.types_map.copy()
          extensions_map.update({
              '': 'application/octet-stream', # Default
              '.py': 'text/plain',
              '.c': 'text/plain',
              '.h': 'text/plain',
              })

      It does *not* uses add_type, but demos the fact that the empty type may be usefull from time to time, maybe don't warn and don't deprecate it at all.

    8. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    9. hugovk commented on Nov 21, 2024

      @hugovk
      hugovk
      on Nov 21, 2024
      Member
      More actions

      Checking the top 8k PyPI projects:

      Details
      ❯ python3 ~/github/misc/cpython/search_pypi_top.py -q . mimetypes.add_type
      ./django_pipeline-3.1.0.tar.gz: django_pipeline-3.1.0/pipeline/utils.py: mimetypes.add_type(type, ext)
      ./dagster-webserver-1.9.0.tar.gz: dagster-webserver-1.9.0/dagster_webserver/webserver.py: mimetypes.add_type("application/javascript", ".js")
      ./dagster-webserver-1.9.0.tar.gz: dagster-webserver-1.9.0/dagster_webserver/webserver.py: mimetypes.add_type("text/css", ".css")
      ./dagster-webserver-1.9.0.tar.gz: dagster-webserver-1.9.0/dagster_webserver/webserver.py: mimetypes.add_type("image/svg+xml", ".svg")
      ./dash-2.18.1.tar.gz: dash-2.18.1/dash/dash.py: mimetypes.add_type("application/json", ".map", True)
      ./chainlit-1.3.1.tar.gz: chainlit-1.3.1/chainlit/server.py: mimetypes.add_type("application/javascript", ".js")
      ./chainlit-1.3.1.tar.gz: chainlit-1.3.1/chainlit/server.py: mimetypes.add_type("text/css", ".css")
      ./ansible-10.5.0.tar.gz: ansible-10.5.0/ansible_collections/azure/azcollection/plugins/modules/azure_rm_storageblob.py: mimetypes.add_type('application/json', '.json')
      ./ansible-10.5.0.tar.gz: ansible-10.5.0/ansible_collections/azure/azcollection/plugins/modules/azure_rm_storageblob.py: mimetypes.add_type('application/javascript', '.js')
      ./ansible-10.5.0.tar.gz: ansible-10.5.0/ansible_collections/azure/azcollection/plugins/modules/azure_rm_storageblob.py: mimetypes.add_type('application/wasm', '.wasm')
      ./django_filer-3.2.3.tar.gz: django_filer-3.2.3/filer/apps.py: mimetypes.add_type("image/heic", ext)
      ./django_filer-3.2.3.tar.gz: django_filer-3.2.3/filer/apps.py: mimetypes.add_type("image/webp", ".webp")
      ./EbookLib-0.18.tar.gz: EbookLib-0.18/ebooklib/utils.py: mimetypes.add_type('application/xhtml+xml', '.xhtml')
      ./fava-1.29.tar.gz: fava-1.29/src/fava/application.py: mimetypes.add_type("text/javascript", ".js")
      ./ansible-10.5.0.tar.gz: ansible-10.5.0/ansible_collections/community/general/tests/integration/targets/launchd/files/ansible_test_service.py: mimetypes.add_type('application/json', '.json')
      ./azure_cli-2.65.0.tar.gz: azure_cli-2.65.0/azure/cli/command_modules/storage/util.py: mimetypes.add_type('application/json', '.json')
      ./azure_cli-2.65.0.tar.gz: azure_cli-2.65.0/azure/cli/command_modules/storage/util.py: mimetypes.add_type('application/javascript', '.js')
      ./azure_cli-2.65.0.tar.gz: azure_cli-2.65.0/azure/cli/command_modules/storage/util.py: mimetypes.add_type('application/wasm', '.wasm')
      ./jupyter_server-2.14.2.tar.gz: jupyter_server-2.14.2/jupyter_server/serverapp.py: mimetypes.add_type("text/css", ".css")
      ./jupyter_server-2.14.2.tar.gz: jupyter_server-2.14.2/jupyter_server/serverapp.py: mimetypes.add_type("application/javascript", ".js")
      ./jupyter_server-2.14.2.tar.gz: jupyter_server-2.14.2/jupyter_server/serverapp.py: mimetypes.add_type("application/wasm", ".wasm")
      ./jupyterlab_server-2.27.3.tar.gz: jupyterlab_server-2.27.3/jupyterlab_server/licenses_handler.py: mimetypes.add_type("text/markdown", ".md")
      ./locust-2.32.1.tar.gz: locust-2.32.1/locust/web.py: mimetypes.add_type("application/javascript", ".js")
      ./openpyxl-3.1.5.tar.gz: openpyxl-3.1.5/openpyxl/packaging/manifest.py: mimetypes.add_type('application/xml', ".xml")
      ./openpyxl-3.1.5.tar.gz: openpyxl-3.1.5/openpyxl/packaging/manifest.py: mimetypes.add_type('application/vnd.openxmlformats-package.relationships+xml', ".rels")
      ./openpyxl-3.1.5.tar.gz: openpyxl-3.1.5/openpyxl/packaging/manifest.py: mimetypes.add_type("application/vnd.ms-office.vbaProject", ".bin")
      ./openpyxl-3.1.5.tar.gz: openpyxl-3.1.5/openpyxl/packaging/manifest.py: mimetypes.add_type("application/vnd.openxmlformats-officedocument.vmlDrawing", ".vml")
      ./openpyxl-3.1.5.tar.gz: openpyxl-3.1.5/openpyxl/packaging/manifest.py: mimetypes.add_type("image/x-emf", ".emf")
      ./panel-1.5.3.tar.gz: panel-1.5.3/panel/io/resources.py: mimetypes.add_type("application/javascript", ".js")
      ./platformio-6.1.16.tar.gz: platformio-6.1.16/platformio/home/cli.py: mimetypes.add_type("text/html", ".html")
      ./platformio-6.1.16.tar.gz: platformio-6.1.16/platformio/home/cli.py: mimetypes.add_type("text/css", ".css")
      ./platformio-6.1.16.tar.gz: platformio-6.1.16/platformio/home/cli.py: mimetypes.add_type("application/javascript", ".js")
      ./nicegui-2.5.0.tar.gz: nicegui-2.5.0/nicegui/nicegui.py: mimetypes.add_type('text/javascript', '.js')
      ./nicegui-2.5.0.tar.gz: nicegui-2.5.0/nicegui/nicegui.py: mimetypes.add_type('text/css', '.css')
      ./robocorp_storage-1.0.5.tar.gz: robocorp_storage-1.0.5/src/robocorp/storage/__init__.py: mimetypes.add_type(type_, ext)
      ./prefect-3.1.0.tar.gz: prefect-3.1.0/src/prefect/server/api/server.py: mimetypes.add_type("application/javascript", ".js")
      ./streamlit-1.39.0.tar.gz: streamlit-1.39.0/streamlit/web/server/app_static_file_handler.py: mimetypes.add_type("image/webp", ".webp")
      ./streamlit-1.39.0.tar.gz: streamlit-1.39.0/streamlit/web/server/component_request_handler.py: mimetypes.add_type("text/html", ".html")
      ./streamlit-1.39.0.tar.gz: streamlit-1.39.0/streamlit/web/server/component_request_handler.py: mimetypes.add_type("application/javascript", ".js")
      ./streamlit-1.39.0.tar.gz: streamlit-1.39.0/streamlit/web/server/component_request_handler.py: mimetypes.add_type("text/css", ".css")
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_converter.py: mimetypes.add_type("image/heic", ".heic")  # to extend types_map
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_converter.py: mimetypes.add_type("image/heif", ".heif")  # to extend types_map
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_converter.py: mimetypes.add_type("image/jpeg", ".jfif")  # to extend types_map
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_converter.py: mimetypes.add_type("image/avif", ".avif")  # to extend types_map
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_converter.py: mimetypes.add_type("image/bmp", ".bmp")  # to extend types_map
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_helper.py: mimetypes.add_type("image/webp", ".webp")  # to extend types_map
      ./supervisely-6.73.221.tar.gz: supervisely-6.73.221/supervisely/convert/image/image_helper.py: mimetypes.add_type("image/jpeg", ".jfif")  # to extend types_map
      ./python_semantic_release-9.12.0.tar.gz: python_semantic_release-9.12.0/semantic_release/hvcs/github.py: mimetypes.add_type("application/octet-stream", ".whl")
      ./python_semantic_release-9.12.0.tar.gz: python_semantic_release-9.12.0/semantic_release/hvcs/github.py: mimetypes.add_type("text/markdown", ".md")
      ./sqlmesh-0.130.1.tar.gz: sqlmesh-0.130.1/web/server/main.py: mimetypes.add_type("application/javascript", ".js")
      ./sqlmesh-0.130.1.tar.gz: sqlmesh-0.130.1/web/server/main.py: mimetypes.add_type("text/css", ".css")
      ./trame-3.7.0.tar.gz: trame-3.7.0/trame/app/mimetypes.py: mimetypes.add_type(key, value)
      ./trame-3.7.0.tar.gz: trame-3.7.0/trame/app/mimetypes.py: mimetypes.add_type(type, ext)
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/png', '.png')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/jpeg', '.jpeg')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/webp', '.webp')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/gif', '.gif')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/bmp', '.bmp')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/x-tga', '.tga')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/tiff', '.tiff')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('image/vnd.adobe.photoshop', '.psd')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('video/mp4', '.mp4')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('video/quicktime', '.mov')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('video/avi', '.avi')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('audio/mpeg', '.mp3')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('audio/m4a', '.m4a')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('audio/aac', '.aac')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('audio/ogg', '.ogg')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('audio/flac', '.flac')
      ./Telethon-1.37.0.tar.gz: Telethon-1.37.0/telethon/utils.py: mimetypes.add_type('application/x-tgsticker', '.tgs')
      ./webob-1.8.9.tar.gz: webob-1.8.9/src/webob/static.py: mimetypes.add_type('text/javascript', '.js') # stdlib default is application/x-javascript
      ./webob-1.8.9.tar.gz: webob-1.8.9/src/webob/static.py: mimetypes.add_type('image/x-icon', '.ico') # not among defaults
      ./webob-1.8.9.tar.gz: webob-1.8.9/tests/test_request.py: mimetypes.add_type('application/x-foo', '.foo')
      ./pyvo-1.6.tar.gz: pyvo-1.6/pyvo/dal/mimetype.py: mimetypes.add_type('application/fits', 'fits')
      ./pyvo-1.6.tar.gz: pyvo-1.6/pyvo/dal/mimetype.py: mimetypes.add_type('application/x-fits', 'fits')
      ./pyvo-1.6.tar.gz: pyvo-1.6/pyvo/dal/mimetype.py: mimetypes.add_type('image/fits', 'fits')
      ./pyvo-1.6.tar.gz: pyvo-1.6/pyvo/dal/mimetype.py: mimetypes.add_type('text/plain', 'txt')
      
      Time: 0:00:26.975038
      Found 77 matching lines in 26 projects

      Of the 77 calls (in 26 projects) to mimetypes.add_type:

      • 68 are dotted
      • 5 (in 4 projects) use a variable. I checked them and the variable uses dotted input.
      • 4 (in 1 project) are undotted. I opened a PR: Add dot to extensions of added MIME types astropy/pyvo#622
    10. hugovk
      added a commit that references this issue on Apr 28, 2025

      gh-75223: Deprecate undotted extensions in `mimetypes.MimeTypes.add_t…

      ee9102a
    11. hugovk commented on Apr 28, 2025

      @hugovk
      hugovk
      on Apr 28, 2025
      Member
      More actions
      • Deprecate in 3.14: gh-75223: Deprecate undotted extensions in mimetypes.MimeTypes.add_type #128638
      • Remove in 3.16
    12. StanFromIreland
      closed this as a duplicateof Remove deprecated feature: ext must start with . in mimetypes.add_type #149720 on May 12, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeend of lifedocsDocumentation in the Doc dirDocumentation in the Doc dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        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.