Skip to content

Commit

Permalink
Handle the case where the raw builder fails to retrieve the ``__all__…
Browse files Browse the repository at this point in the history
…`` attribute

PyQT does something special with their objects and retrieving some of
them (such as `__all__`) at runtime results in a RuntimeError.
This patch simply swallows all the exceptions that accessing `__all__`
might raise.

Close #772
  • Loading branch information
PCManticore committed Apr 28, 2020
1 parent 7e17162 commit 5e7aed7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
astroid's ChangeLog
===================


What's New in astroid 2.5.0?
============================
Release Date: TBA


What's New in astroid 2.4.1?
============================
Release Date: TBA

* Handle the case where the raw builder fails to retrieve the ``__all__`` attribute

Close #772


What's New in astroid 2.4.0?
============================
Release Date: 2020-04-27
Expand Down
9 changes: 8 additions & 1 deletion astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ def _build_from_function(node, name, member, module):
object_build_function(node, member, name)


def _safe_has_attribute(obj, member):
try:
return hasattr(obj, member)
except Exception: # pylint: disable=broad-except
return False


class InspectBuilder:
"""class for building nodes from living object
Expand Down Expand Up @@ -357,7 +364,7 @@ def object_build(self, node, obj):
# This should be called for Jython, where some builtin
# methods aren't caught by isbuiltin branch.
_build_from_function(node, name, member, self._module)
elif hasattr(member, "__all__"):
elif _safe_has_attribute(member, "__all__"):
module = build_module(name)
_attach_local_node(node, module, name)
# recursion
Expand Down

0 comments on commit 5e7aed7

Please sign in to comment.