Skip to content

Commit

Permalink
This is sort of unrelated, but I found a few cases in testing where t…
Browse files Browse the repository at this point in the history
…his fix was needed. This is more of a followup to astropy#130 to catch some more cases where simply calling getattr() on some objects can result in a non-AttributeError exception.
  • Loading branch information
embray committed Mar 28, 2015
1 parent 6bdb8a4 commit 75ec678
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions astropy_helpers/sphinx/ext/autodoc_enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ def type_object_attrgetter(obj, attr, *defargs):
of autodoc.
"""

if attr in obj.__dict__ and isinstance(obj.__dict__[attr], property):
# Note, this should only be used for properties--for any other type of
# descriptor (classmethod, for example) this can mess up existing
# expectcations of what getattr(cls, ...) returns
return obj.__dict__[attr]
else:
return getattr(obj, attr, *defargs)
for base in obj.__mro__:
if attr in base.__dict__:
if isinstance(base.__dict__[attr], property):
# Note, this should only be used for properties--for any other
# type of descriptor (classmethod, for example) this can mess
# up existing expectations of what getattr(cls, ...) returns
return base.__dict__[attr]
break

return getattr(obj, attr, *defargs)


def setup(app):
Expand Down
5 changes: 3 additions & 2 deletions astropy_helpers/sphinx/ext/viewcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sphinx import addnodes
from sphinx.locale import _
from sphinx.pycode import ModuleAnalyzer
from sphinx.util.inspect import safe_getattr
from sphinx.util.nodes import make_refnode

import sys
Expand Down Expand Up @@ -51,12 +52,12 @@ def get_full_modname(modname, attribute):
value = module
for attr in attribute.split('.'):
if attr:
value = getattr(value, attr)
value = safe_getattr(value, attr)
except AttributeError:
app.warn('Didn\'t find %s in %s' % (attribute, module.__name__))
return None
else:
return getattr(value, '__module__', None)
return safe_getattr(value, '__module__', None)


def has_tag(modname, fullname, docname, refname):
Expand Down

0 comments on commit 75ec678

Please sign in to comment.