Title: mimetypes.guess_all_extensions potentially mutates list
Type: behavior Stage:
Components: Library (Lib) Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: rmccampbell7
Priority: normal Keywords:

Created on 2018-12-12 19:06 by rmccampbell7, last changed 2018-12-12 19:06 by rmccampbell7.

Messages (1)
msg331715 - (view) Author: Ryan McCampbell (rmccampbell7) Date: 2018-12-12 19:06
The mimetypes.guess_all_extensions function is defined as:

def guess_all_extensions(self, type, strict=True):
    type = type.lower()
    extensions = self.types_map_inv[True].get(type, [])
    if not strict:
        for ext in self.types_map_inv[False].get(type, []):
            if ext not in extensions:
    return extensions

If any mime type exists in both the strict and non-strict types_map_inv and it is called with strict=False, then it will modify the strict list in-place which effects future calls even with strict=True. While this doesn't manifest as an error for me because the dictionaries are non-overlapping, it is a potential error; it is also vulnerable to people accidentally modifying the returned list. The list should be copied after the first lookup.
Date User Action Args
2018-12-12 19:06:57rmccampbell7create