[docs] Bug in mimetypes.MimeTypes documentation

Łukasz Cieśnik lukasz.ciesnik at gmail.com
Thu Jun 9 10:38:43 CEST 2011


Hello,

I have found that MimeTypes class does not provide same interface
as mimetypes module does in terms of ``types_map`` and ``common_types``
attributes.  There is no ``common_types`` dictionary found in
MimeTypes instances and ``types_map`` is a tuple of (non_strict, strict)
extension to mime type mappings:

  Python 2.7.1 (r271:86832, Nov 27 2010, 17:19:03) [MSC v.1500 64 bit
(AMD64)] on win32
  Type "help", "copyright", "credits" or "license" for more information.
  >>> import mimetypes
  >>> m = mimetypes.MimeTypes()
  >>> type(m.types_map)
  <type 'tuple'>
  >>> m.common_types
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  AttributeError: MimeTypes instance has no attribute 'common_types'
  >>> m.types_map[True]
  {'.obj': 'application/octet-stream', '.ra': 'audio/x-pn-realaudio',
'.dwfx': 'model/vnd.dwfx+xps', '.wsdl': 'application/xml', [...]
'.wvx': 'video/x-ms-wvx'}
  >>> m.types_map[False]
  {'.xul': 'text/xul', '.pic': 'image/pict', '.pict': 'image/pict',
'.jpg': 'image/jpg', '.rtf': 'application/rtf', '.pct': 'image/pict',
'.mid': 'audio/midi', '.midi': 'audio/midi'}

At the same time documentation advertises this quite differently:

  18.7.1. MimeTypes Objects
  http://docs.python.org/library/mimetypes.html#mimetypes-objects

  .. attribute:: MimeTypes.types_map

     Dictionary mapping filename extensions to MIME types.  This is
initially a copy
     of the global ``types_map`` defined in the module.


  .. attribute:: MimeTypes.common_types

     Dictionary mapping filename extensions to non-standard, but
commonly found MIME
     types.  This is initially a copy of the global ``common_types``
defined in the
     module.

It would be nice if it resembled module interface, so this might be a
code issue as well.
Nevertheless currently documentation says something different than code does.

Thanks,

-- 
Łukasz Cieśnik


More information about the docs mailing list