Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: can't compute signature for built-in type <class 'str'> error when building api docs #7791

Closed
NucleaPeon opened this issue Jun 5, 2020 · 7 comments

Comments

@NucleaPeon
Copy link

Describe the bug
Running sphinx-build after sphinx-apidoc on our codebase results in the error message:

TypeError: can't compute signature for built-in type <class 'str'>

The exact command I ran is make html with everything set up and the .rsts generated.

To Reproduce
make html

Due to the specifics and the company I work for, I am unable to provide a complete code example, but I can provide the module in its entirety that it was tripping up on and it doesn't contain specifics.

import collections
import argparse


class Namespace(argparse.Namespace):

    @property
    def vs(self):
        return vars(self)


def make_default_ns_dict_class(namespace=Namespace):
    class DefaultNamespaceDict(collections.defaultdict):
        def __init__(self, *args, **kwargs):
            super().__init__(namespace, *args, **kwargs)
    return DefaultNamespaceDict


NS = Namespace
NamespaceDict = make_default_ns_dict_class()

Expected behavior
No errors when running make html

Your project
n/a

Environment info

  • OS: Gentoo Linux, KDE 19.12.3, Plasma 5.70
  • Python version: 3.7.7
  • Sphinx version: See below
  • Sphinx extensions: See below
  • Extra tools: n/a
alabaster                          0.7.12            
autodoc                            0.5.0             
Babel                              2.8.0             
beautifulsoup4                     4.9.1             
Brotli                             1.0.7             
bsddb3                             6.2.4             
certifi                            2020.4.5.1        
cffi                               1.14.0            
chardet                            3.0.4             
cracklib                           2.9.7             
cryptacular                        1.4.1
cryptography                       2.8               
Cython                             0.29.15           
decorator                          4.4.2             
distro                             1.0.4             
docutils                           0.16              
extras                             1.0.0             
file-magic                         0.4.0             
fixtures                           3.0.0             
FormEncode                         1.3.1             
gdbus-codegen                      2.62.6            
gemato                             14.3              
gentoolkit                         0.4.8             
gpg                                1.13.0            
gpodder                            3.10.5            
html5lib                           1.0.1             
idna                               2.8               
imagesize                          1.1.0             
isodate                            0.6.0             
isort                              4.3.15            
java-config                        2.2.0             
Jinja2                             2.11.1            
layman                             2.4.3             
lensfun                            0.3.2             
libsass                            0.20.0            
linecache2                         1.0.0             
lxml                               4.5.0             
M2Crypto                           0.31.0            
Mako                               1.1.2             
Markdown                           2.4.1             
Markups                            3.0.0             
MarkupSafe                         1.1.1             
mercurial                          5.3.2             
meson                              0.52.1            
mimeparse                          1.6.0             
mock                               4.0.2             
Momoko                             2.2.5.1           
mygpoclient                        1.8               
netlink                            1.0               
notify2                            0.3.1             
numpy                              1.17.4            
olefile                            0.46              
packaging                          20.3              
pbkdf2                             1.3               
pbr                                4.2.0             
pdoc                               0.3.2             
Pillow                             7.0.0             
pip                                20.0.2            
ply                                3.11              
podcastparser                      0.6.4             
portage                            2.3.99            
psycopg2                           2.8.5             
psycopg2-binary                    2.8.5             
pwquality                          1.4.2             
pycairo                            1.18.2            
pycountry                          19.8.18           
pycparser                          2.20              
pycryptodome                       3.9.4             
pyelftools                         0.25              
pyenchant                          2.0.0             
Pygments                           2.5.2             
PyGObject                          3.34.0            
pyOpenSSL                          19.1.0            
pyparsing                          2.4.6             
pyportmidi                         0.0.7             
PyQt5                              5.14.1            
PyQt5-sip                          4.19.21           
PyQtWebEngine                      5.14.0            
pyrsistent                         0.15.6            
PySocks                            1.7.1             
python-markdown-math               0.6               
python-mimeparse                   1.6.0             
python-subunit                     1.2.0             
pytz                               2019.3            
pyxdg                              0.26              
PyYAML                             5.3.1             
rdflib                             4.2.2             
reportlab                          3.5.13            
requests                           2.23.0            
ReText                             7.0.4             
scour                              0.37              
setuptools                         44.1.0            
simplejson                         3.17.0            
sip                                4.19.21           
six                                1.14.0            
snowballstemmer                    2.0.0             
soupsieve                          2.0.1             
Sphinx                             3.0.4             
sphinx-rtd-theme                   0.4.3             
sphinx-rtd-theme-http              1.0.0             
sphinxcontrib-apidoc               0.3.0             
sphinxcontrib-applehelp            1.0.2             
sphinxcontrib-autodoc-doxygen      0.6.0             
sphinxcontrib-autodoc-filterparams 0.0.1             
sphinxcontrib-devhelp              1.0.2             
sphinxcontrib-htmlhelp             1.0.3             
sphinxcontrib-jsmath               1.0.1             
sphinxcontrib-mockautodoc          0.0.1.dev20130518 
sphinxcontrib-qthelp               1.0.3             
sphinxcontrib-serializinghtml      1.1.3             
ssl-fetch                          0.4               
testtools                          2.3.0             
tornado                            5.1.1             
traceback2                         1.4.0             
typed-ast                          1.4.1             
unittest2                          1.1.0             
urllib3                            1.25.8            
waitress                           1.4.4             
webencodings                       0.5.1             
WebOb                              1.8.6             
WebTest                            2.0.35            
youtube-dl                         2020.5.29         
zstandard                          0.13.0

Additional context
See attachment

sphinx-err-wzrazkn1.log

@tk0miya
Copy link
Member

tk0miya commented Jun 5, 2020

Thank you for reporting. The attached error log says Sphinx was crashed in processing a singledispatch function. Does your module contain a singledispatch function?

@tk0miya tk0miya added this to the 3.1.0 milestone Jun 5, 2020
@NucleaPeon
Copy link
Author

Does your module contain a singledispatch function?

If you're referring to the namespace module code I posted, then no. It's only relying on official python libraries. I don't think defaultdict uses a singledispatch and I did look at some of the source for it. We have other places where we use argparse and Namespace and we don't get that error so I don't think those are responsible.

Part of how I tested was I found the overall sub-module in the codebase that was producing the stacktrace, then I moved out all the modules and slowly added them back in until I found which module caused it. Perhaps it's in conjunction with another module, I don't know, but that's how I arrived at the above issue.

We do have singledispatch-enabled functions in our codebase, it's mostly used in json encoding for serialization and our json python module isn't producing the stacktrace, at least without our namespace one.
I wish I could be more help, let me know what else I can try or if you need more information.

@tk0miya
Copy link
Member

tk0miya commented Jun 6, 2020

@NucleaPeon Could you confirm this PR #7797 resolves your problem?
You can install it by pip install git+https://github.com/tk0miya/sphinx.git@7791_TypeError_for_singledispatchfunction

@tk0miya tk0miya closed this as completed in f98987b Jun 8, 2020
tk0miya added a commit that referenced this issue Jun 8, 2020
…chfunction

Fix #7791: autodoc: TypeError is raised on documenting singledispatch function
@tk0miya
Copy link
Member

tk0miya commented Jun 8, 2020

I merged #7797 and going to release it as 3.1.0. Could you check the new package, please? And please let me know if not working fine.

@NucleaPeon
Copy link
Author

NucleaPeon commented Jun 8, 2020

Looks like we got further!


Running Sphinx v3.1.0
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 41 source files that are out of date
updating environment: [new config] 41 added, 0 changed, 0 removed
reading sources... [ 87%] ...                                                                                                                                                                
Exception occurred:
  File "/home/danielk/.local/lib/python3.7/site-packages/sphinx/ext/autodoc/__init__.py", line 1240, in annotate_to_first_argument
    func.__signature__ = sig.replace(parameters=params)  # type: ignore
TypeError: can't set attributes of built-in/extension type 'list'
The full traceback has been saved in /tmp/sphinx-err-lf0wsvvp.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!
make[1]: *** [Makefile:20: html] Error 2
make[1]: Leaving directory '/home/danielk/Development/docs'
make: *** [Makefile:85: docs] Error 2

sphinx-err-lf0wsvvp.log

Should I refile the issue? Not sure I can reopen this issue.

@tk0miya
Copy link
Member

tk0miya commented Jun 11, 2020

Could you file a new issue, please? It seems the error is not related to this.

@tk0miya
Copy link
Member

tk0miya commented Jun 11, 2020

Note: The error log says autofunction diretive takes an overloaded function. But it failed to update the __signature__ attribute because given function is a built-in class list (or similar type). I don't understand why list like class is passed to the overloaded function. Anyway, we should handle the TypeError here.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants