Sphinx: TypeError: type object argument after ** must be a mapping, not Sphinx

Created on 21 Apr 2018  路  4Comments  路  Source: sphinx-doc/sphinx

Subject: TypeError: type object argument after ** must be a mapping, not Sphinx

Problem

  • Cant use sphinx because the sphinxcontrib.googleanalytics package throws an error.

Procedure to reproduce the problem

make html
sphinx-build -b html -d build/doctrees   source build/html

Error logs / results

Python 3.6.3
$ sphinx-build -b html -d build/doctrees   source build/html
Running Sphinx v1.7.2
WARNING: extension 'sphinxcontrib.googleanalytics' returned an unsupported object from its setup() function; it should return None or a metadata dictionary

Exception occurred:
  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
The full traceback has been saved in /tmp/sphinx-err-c4n8npty.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
Makefile:55: recept voor doel 'html' is mislukt
make: *** [html] Fout 2
# 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
Python 2.7.12
$ python2.7 /usr/local/bin/sphinx-build -b latex -d build/doctrees   source build/latex
Running Sphinx v1.7.2
WARNING: extension 'sphinxcontrib.googleanalytics' returned an unsupported object from its setup() function; it should return None or a metadata dictionary

Exception occurred:
  File "/usr/local/lib/python2.7/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
The full traceback has been saved in /tmp/sphinx-err-AqY4hJ.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
# Sphinx version: 1.7.2
# Python version: 2.7.12 (CPython)
# Docutils version: 0.14 
# Jinja2 version: 2.10
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/sphinx/cmdline.py", line 303, in main
    args.warningiserror, args.tags, args.verbosity, args.jobs)
  File "/usr/local/lib/python2.7/dist-packages/sphinx/application.py", line 191, in __init__
    self.setup_extension(extension)
  File "/usr/local/lib/python2.7/dist-packages/sphinx/application.py", line 411, in setup_extension
    self.registry.load_extension(self, extname)
  File "/usr/local/lib/python2.7/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

Reproducible project / your project

Environment info

  • OS: Kernel: x86_64 Linux 4.10.0-22-generic
  • Python version: Python 3.6.3 & 2.7.12
  • Sphinx version: sphinx-build 1.7.2
bug extensions

Most helpful comment

Indeed, this problem came from wrong extension. But Sphinx should not be crashed even if broken extensions are loaded.
So I'll work for it from now on.

All 4 comments

Yes, the sphinxcontrib-googleanalytics installed by pip contains

def setup(app):
    app.add_config_value('googleanalytics_id', '', 'html')
    app.add_config_value('googleanalytics_enabled', True, 'html')
    app.connect('html-page-context', add_ga_javascript)
    app.connect('builder-inited', check_config)
    return app

but the source available here contains

def setup(app):
    app.add_config_value('googleanalytics_id', '', 'html')
    app.add_config_value('googleanalytics_enabled', True, 'html')
    app.connect('html-page-context', add_ga_javascript)
    app.connect('builder-inited', check_config)
return {'version': '0.1'}

Only the latter version is compatible with Sphinx loading of extension. But the metada of the pip installed one does say version is 0.1. And bitbucket source has the correct return statement.

It seems commit from 2015-08-11 is not merged into pip distributed package???

Indeed from there it seems afaict that the pip packaging was not updated. Can you report it upstream to the bitbucket site as an issue?

I have reported the issue to their bitbucket repo. For now, I manually changed that rule of code.

Thanks!

Indeed, this problem came from wrong extension. But Sphinx should not be crashed even if broken extensions are loaded.
So I'll work for it from now on.

Fixed by #4883.
Thank you for reporting!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oonid picture oonid  路  3Comments

shimizukawa picture shimizukawa  路  3Comments

tuomas2 picture tuomas2  路  3Comments

shimizukawa picture shimizukawa  路  3Comments

shimizukawa picture shimizukawa  路  3Comments