Skip to content

Fix missing __dict__ #2685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion astroid/raw_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,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~=6.0
mypy
7 changes: 7 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,6 +33,7 @@
build_from_import,
build_function,
build_module,
object_build_class,
)

DUMMY_MOD = build_module("DUMMY")
Expand Down Expand Up @@ -160,3 +162,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)
Loading