Skip to content

Commit eed7458

Browse files
authored
Fix missing __dict__ (#2685)
1 parent 71dc6b2 commit eed7458

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
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:

requirements_dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
black
55
pre-commit
66
pylint>=3.2.7
7-
mypy
87
ruff

requirements_minimal.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ tbump~=6.11
66
coverage~=7.6
77
pytest
88
pytest-cov~=6.0
9+
mypy

tests/test_raw_building.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from typing import Any
2020
from unittest import mock
2121

22+
import mypy.build
2223
import pytest
2324

2425
import tests.testdata.python3.data.fake_module_with_broken_getattr as fm_getattr
@@ -33,6 +34,7 @@
3334
build_from_import,
3435
build_function,
3536
build_module,
37+
object_build_class,
3638
)
3739

3840
DUMMY_MOD = build_module("DUMMY")
@@ -169,3 +171,8 @@ def mocked_sys_modules_getitem(name: str) -> types.ModuleType | CustomGetattr:
169171
assert expected_err in caplog.text
170172
assert not out
171173
assert not err
174+
175+
176+
def test_missing__dict__():
177+
# This shouldn't raise an exception.
178+
object_build_class(DUMMY_MOD, mypy.build.ModuleNotFound)

0 commit comments

Comments
 (0)