# Buggy code
def load_extension(self, app, extname):
    # type: (Sphinx, unicode) -> None
    """Load a Sphinx extension."""
    if extname in app.extensions:  # alread loaded
        return
    if extname in EXTENSION_BLACKLIST:
        logger.warning(
            __(
                "the extension %r was already merged with Sphinx since "
                "version %s; this extension is ignored."
            ),
            extname,
            EXTENSION_BLACKLIST[extname],
        )
        return

    # update loading context
    app._setting_up_extension.append(extname)

    try:
        mod = __import__(extname, None, None, ["setup"])
    except ImportError as err:
        logger.verbose(__("Original exception:\n") + traceback.format_exc())
        raise ExtensionError(__("Could not import extension %s") % extname, err)

    if not hasattr(mod, "setup"):
        logger.warning(
            __(
                "extension %r has no setup() function; is it really "
                "a Sphinx extension module?"
            ),
            extname,
        )
        metadata = {}  # type: Dict[unicode, Any]
    else:
        try:
            metadata = mod.setup(app)
        except VersionRequirementError as err:
            # add the extension name to the version required
            raise VersionRequirementError(
                __(
                    "The %s extension used by this project needs at least "
                    "Sphinx v%s; it therefore cannot be built with this "
                    "version."
                )
                % (extname, err)
            )

    if metadata is None:
        metadata = {}
        if extname == "rst2pdf.pdfbuilder":
            metadata["parallel_read_safe"] = True
    elif not isinstance(metadata, dict):
        logger.warning(
            __(
                "extension %r returned an unsupported object from "
                "its setup() function; it should return None or a "
                "metadata dictionary"
            ),
            extname,
        )

    app.extensions[extname] = Extension(extname, mod, **metadata)
    app._setting_up_extension.pop()


# Traceback (TypeError)
# Sphinx version: 1.7.2
# Python version: 3.6.3 (CPython)
# Docutils version: 0.14
# Jinja2 version: 2.10
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/sphinx/cmdline.py", line 303, in main
args.warningiserror, args.tags, args.verbosity, args.jobs)
File "/usr/local/lib/python3.6/dist-packages/sphinx/application.py", line 191, in __init__
self.setup_extension(extension)
File "/usr/local/lib/python3.6/dist-packages/sphinx/application.py", line 411, in setup_extension
self.registry.load_extension(self, extname)
File "/usr/local/lib/python3.6/dist-packages/sphinx/registry.py", line 344, in load_extension
app.extensions[extname] = Extension(extname, mod, **metadata)
TypeError: type object argument after ** must be a mapping, not Sphinx

# Fixed code
def load_extension(self, app, extname):
    # type: (Sphinx, unicode) -> None
    """Load a Sphinx extension."""
    if extname in app.extensions:  # alread loaded
        return
    if extname in EXTENSION_BLACKLIST:
        logger.warning(
            __(
                "the extension %r was already merged with Sphinx since "
                "version %s; this extension is ignored."
            ),
            extname,
            EXTENSION_BLACKLIST[extname],
        )
        return

    # update loading context
    app._setting_up_extension.append(extname)

    try:
        mod = __import__(extname, None, None, ["setup"])
    except ImportError as err:
        logger.verbose(__("Original exception:\n") + traceback.format_exc())
        raise ExtensionError(__("Could not import extension %s") % extname, err)

    if not hasattr(mod, "setup"):
        logger.warning(
            __(
                "extension %r has no setup() function; is it really "
                "a Sphinx extension module?"
            ),
            extname,
        )
        metadata = {}  # type: Dict[unicode, Any]
    else:
        try:
            metadata = mod.setup(app)
        except VersionRequirementError as err:
            # add the extension name to the version required
            raise VersionRequirementError(
                __(
                    "The %s extension used by this project needs at least "
                    "Sphinx v%s; it therefore cannot be built with this "
                    "version."
                )
                % (extname, err)
            )

    if metadata is None:
        metadata = {}
        if extname == "rst2pdf.pdfbuilder":
            metadata["parallel_read_safe"] = True
    elif not isinstance(metadata, dict):
        logger.warning(
            __(
                "extension %r returned an unsupported object from "
                "its setup() function; it should return None or a "
                "metadata dictionary"
            ),
            extname,
        )
        metadata = {}

    app.extensions[extname] = Extension(extname, mod, **metadata)
    app._setting_up_extension.pop()