import os
import mimetypes

HERE = os.path.dirname(os.path.abspath(__file__))
MIMEMAP = os.path.join(HERE, 'mime.types')


def get_mimetype(path, data=None):
    mimetypes.init([MIMEMAP])
    mimetype, _ = mimetypes.guess_type(path)

    if mimetype is None and data is not None:
        try:
            import magic
            mimetype = magic.from_buffer(data, mime=True)
        except ImportError:
            return mimetype

    return mimetype
import os
import mimetypes

HERE = os.path.dirname(os.path.abspath(__file__))
MIMEMAP = os.path.join(HERE, 'mime.types')


def get_mimetype(path, file_contents=None):
    mimetypes.init([MIMEMAP])
    mimetype, _ = mimetypes.guess_type(path)

    if mimetype is None and file_contents is not None:
        try:
            import magic
            mimetype = magic.from_buffer(file_contents, mime=True)
        except ImportError:
            return mimetype

    return mimetype
Make better name for argument.
Make better name for argument.

  import os
  import mimetypes
  
  HERE = os.path.dirname(os.path.abspath(__file__))
  MIMEMAP = os.path.join(HERE, 'mime.types')
  
  
- def get_mimetype(path, data=None):
+ def get_mimetype(path, file_contents=None):
      mimetypes.init([MIMEMAP])
      mimetype, _ = mimetypes.guess_type(path)
  
-     if mimetype is None and data is not None:
+     if mimetype is None and file_contents is not None:
          try:
              import magic
-             mimetype = magic.from_buffer(data, mime=True)
+             mimetype = magic.from_buffer(file_contents, mime=True)
          except ImportError:
              return mimetype
  
      return mimetype
Make better name for argument.
## Code Before:
import os
import mimetypes

HERE = os.path.dirname(os.path.abspath(__file__))
MIMEMAP = os.path.join(HERE, 'mime.types')


def get_mimetype(path, data=None):
    mimetypes.init([MIMEMAP])
    mimetype, _ = mimetypes.guess_type(path)

    if mimetype is None and data is not None:
        try:
            import magic
            mimetype = magic.from_buffer(data, mime=True)
        except ImportError:
            return mimetype

    return mimetype
## Instruction:
Make better name for argument.
## Code After:
import os
import mimetypes

HERE = os.path.dirname(os.path.abspath(__file__))
MIMEMAP = os.path.join(HERE, 'mime.types')


def get_mimetype(path, file_contents=None):
    mimetypes.init([MIMEMAP])
    mimetype, _ = mimetypes.guess_type(path)

    if mimetype is None and file_contents is not None:
        try:
            import magic
            mimetype = magic.from_buffer(file_contents, mime=True)
        except ImportError:
            return mimetype

    return mimetype