Skip to content

Commit 199ce1c

Browse files
committed
Fix missing __dict__
1 parent fe893d9 commit 199ce1c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

astroid/raw_building.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,11 @@ def _base_class_object_build(
369369
# this at least resolves common case such as Exception.args,
370370
# OSError.errno
371371
if issubclass(member, Exception):
372-
instdict = member().__dict__
372+
member_object = member()
373+
if hasattr(member_object, "__dict__"):
374+
instdict = member_object.__dict__
375+
else:
376+
raise TypeError
373377
else:
374378
raise TypeError
375379
except TypeError:

tests/test_raw_building.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
build_from_import,
3333
build_function,
3434
build_module,
35+
object_build_class,
3536
)
3637

3738
DUMMY_MOD = build_module("DUMMY")
@@ -160,3 +161,12 @@ def mocked_sys_modules_getitem(name: str) -> types.ModuleType | CustomGetattr:
160161
assert expected_err in caplog.text
161162
assert not out
162163
assert not err
164+
165+
166+
def test_missing__dict__():
167+
# This shouldn't raise an exception.
168+
class TestError(Exception):
169+
def __init__(self):
170+
del self.__dict__
171+
172+
object_build_class(build_module(_io.__name__), TestError)

0 commit comments

Comments
 (0)