summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-01-10 23:18:16 +0100
committerGitHub <noreply@github.com>2023-01-10 22:18:16 +0000
commit9eb8c47ddb6b48e14dbdb87bb1b02fcb580cb20d (patch)
treed653afb5983cf7a4338b491edc5c06650371ab05 /astroid
parent49691cc04f2d38b174787280f7ed38f818c828bd (diff)
downloadastroid-git-9eb8c47ddb6b48e14dbdb87bb1b02fcb580cb20d.tar.gz
Fix a regression in 2.13.2 where a ``RunTimeError`` could be raised unexpectedly (#1959)
* Add a unit test for broken __getattr__ in extension modules Co-authored-by: Florian Bruhin <me@the-compiler.org> Closes #1958
Diffstat (limited to 'astroid')
-rw-r--r--astroid/raw_building.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/astroid/raw_building.py b/astroid/raw_building.py
index fe19bb75..cc3aa015 100644
--- a/astroid/raw_building.py
+++ b/astroid/raw_building.py
@@ -324,6 +324,17 @@ def _build_from_function(
object_build_function(node, member, name)
+def _safe_has_attribute(obj, member: str) -> bool:
+ """Required because unexpected RunTimeError can be raised.
+
+ See https://github.com/PyCQA/astroid/issues/1958
+ """
+ try:
+ return hasattr(obj, member)
+ except Exception: # pylint: disable=broad-except
+ return False
+
+
class InspectBuilder:
"""class for building nodes from living object
@@ -419,7 +430,7 @@ class InspectBuilder:
# 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