Recover from exceptions in autodoc's isdescriptor function

Hao Lian avatarHao Lian created an issue

The line in question is

if hasattr(getattr(x, item, None), '__call__'):

For Paste Registry proxy classes, getattr raises an exception by design if the Paste Registry object has yet to be registered, which it usually isn't in the course of the Sphinx build. (Paste Registry is a thread-safe deferred global WSGI middleware package. You basically assign an empty proxy object to a global and then register it with a real object when the WSGI application is called. Of course, when Sphinx accesses the class, there's no WSGI environment or application to do so.)

Paste Registry, and therefore this uncaught exception, notably occurs in all Pylons applications.

I don't know if this would be acceptable given the fact that getattr usually will never behave this way, but a simple work-around would be to surround the getattr with a try-catch block and simply return False on all exceptions caught.

This seems to be the only problem Paste Registry has with autodoc; after applying this change, Pylons and autodoc seem to get along great. From a cursory glance, I'm guessing it's the only place in the code to actually try and access a class member, and thus the only place to trigger the exception.

Here is a snipped backtrace when autodoc tries to inspect the "url" proxied global in Pylons:

  File "[snip]/autodoc.py", line 1019, in can_document_member
    return (isdescriptor(member) and not
  File "[snip]/autodoc.py", line 203, in isdescriptor
    if hasattr(getattr(x, item, None), '__call__'):
  File "[snip]/paste/registry.py", line 137, in __getattr__
    return getattr(self._current_obj(), attr)
  File "[snip]/paste/registry.py", line 194, in _current_obj
    'thread' % self.____name__)
TypeError: No object (name: url) has been registered for this thread

Comments (1)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.