Skip to content

Incorrect docs for mimetypes.MimeTypes.types_map #115075

@maxnikulin

Description

@maxnikulin

.. attribute:: MimeTypes.types_map
Tuple containing two dictionaries, mapping filename extensions to MIME types:
the first dictionary is for the non-standards types and the second one is for
the standard types. They are initialized by :data:`common_types` and
:data:`types_map`.

Notice

They are initialized by common_types and types_map.

The same is applicable for MimeTypes.types_map_inv. Try

import mimetypes

mimetypes.init()
mimetypes.types_map[".ae1"] = "application/pers.added"
db = mimetypes.MimeTypes()
print(db.types_map[True].get(".ae1"))

it reports

None

Accordingly to the docs I would expect application/pers.added. It can be achieved by commenting out the mimetypes.init() call.

I think, behavior changed when #49213 was fixed, but docs have not been updated.

I see some reason in the documented behavior. Perhaps mimetypes.init() should be more flexible and support both ways to set types_map: from the global dictionary and from the internal data, but likely it should be discussed on the pyhton-ideas mailing list first.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy