Skip to content

Commit aad8e68

Browse files
[Backport maintenance/3.3.x] Fix missing __dict__ (#2685) (#2690)
Co-authored-by: Stéphane Brunner <[email protected]>
1 parent 234be58 commit aad8e68

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.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~=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
@@ -32,8 +33,11 @@
3233
build_from_import,
3334
build_function,
3435
build_module,
36+
object_build_class,
3537
)
3638

39+
DUMMY_MOD = build_module("DUMMY")
40+
3741

3842
class RawBuildingTC(unittest.TestCase):
3943
def test_attach_dummy_node(self) -> None:
@@ -166,3 +170,8 @@ def mocked_sys_modules_getitem(name: str) -> types.ModuleType | CustomGetattr:
166170
assert expected_err in caplog.text
167171
assert not out
168172
assert not err
173+
174+
175+
def test_missing__dict__():
176+
# This shouldn't raise an exception.
177+
object_build_class(DUMMY_MOD, mypy.build.ModuleNotFound, "arbitrary_name")

0 commit comments

Comments
 (0)