Skip to content

Commit 835fd99

Browse files
sbrunnerPierre-Sassoulas
authored andcommitted
Fix missing __dict__ (#2685)
1 parent d52799b commit 835fd99

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

astroid/raw_building.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ def _base_class_object_build(
370370
# this at least resolves common case such as Exception.args,
371371
# OSError.errno
372372
if issubclass(member, Exception):
373-
instdict = member().__dict__
373+
member_object = member()
374+
if hasattr(member_object, "__dict__"):
375+
instdict = member_object.__dict__
376+
else:
377+
raise TypeError
374378
else:
375379
raise TypeError
376380
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.0
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~=5.0
9+
mypy

tests/test_raw_building.py

Lines changed: 9 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
@@ -31,8 +32,11 @@
3132
build_from_import,
3233
build_function,
3334
build_module,
35+
object_build_class,
3436
)
3537

38+
DUMMY_MOD = build_module("DUMMY")
39+
3640

3741
class RawBuildingTC(unittest.TestCase):
3842
def test_attach_dummy_node(self) -> None:
@@ -157,3 +161,8 @@ def mocked_sys_modules_getitem(name: str) -> types.ModuleType | CustomGetattr:
157161
assert expected_err in caplog.text
158162
assert not out
159163
assert not err
164+
165+
166+
def test_missing__dict__():
167+
# This shouldn't raise an exception.
168+
object_build_class(DUMMY_MOD, mypy.build.ModuleNotFound)

0 commit comments

Comments
 (0)