Skip to content

Commit

Permalink
[Backport maintenance/3.3.x] Fix missing __dict__ (#2685) (#2690)
Browse files Browse the repository at this point in the history
Co-authored-by: Stéphane Brunner <stephane.brunner@camptocamp.com>
  • Loading branch information
Pierre-Sassoulas and sbrunner authored Mar 2, 2025
1 parent 234be58 commit aad8e68
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ def _base_class_object_build(
# this at least resolves common case such as Exception.args,
# OSError.errno
if issubclass(member, Exception):
instdict = member().__dict__
member_object = member()
if hasattr(member_object, "__dict__"):
instdict = member_object.__dict__
else:
raise TypeError
else:
raise TypeError
except TypeError:
Expand Down
1 change: 0 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
black
pre-commit
pylint>=3.2.7
mypy
ruff
1 change: 1 addition & 0 deletions requirements_minimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tbump~=6.11
coverage~=7.6
pytest
pytest-cov~=5.0
mypy
9 changes: 9 additions & 0 deletions tests/test_raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Any
from unittest import mock

import mypy.build
import pytest

import tests.testdata.python3.data.fake_module_with_broken_getattr as fm_getattr
Expand All @@ -32,8 +33,11 @@
build_from_import,
build_function,
build_module,
object_build_class,
)

DUMMY_MOD = build_module("DUMMY")


class RawBuildingTC(unittest.TestCase):
def test_attach_dummy_node(self) -> None:
Expand Down Expand Up @@ -166,3 +170,8 @@ def mocked_sys_modules_getitem(name: str) -> types.ModuleType | CustomGetattr:
assert expected_err in caplog.text
assert not out
assert not err


def test_missing__dict__():
# This shouldn't raise an exception.
object_build_class(DUMMY_MOD, mypy.build.ModuleNotFound, "arbitrary_name")

0 comments on commit aad8e68

Please sign in to comment.