diff --git a/src/runtime/Types/ReflectedClrType.cs b/src/runtime/Types/ReflectedClrType.cs index 43d2f989d..01ec68d21 100644 --- a/src/runtime/Types/ReflectedClrType.cs +++ b/src/runtime/Types/ReflectedClrType.cs @@ -331,10 +331,15 @@ static bool TryGetBuiltinAttr(BorrowedReference ob, BorrowedReference key, out N return false; } - if (keyStr == nameof(PyIdentifier.__init__)) + switch (keyStr) { - result = Runtime.PyObject_GenericGetAttr(ob, key); - return true; + case nameof(PyIdentifier.__init__): + result = Runtime.PyObject_GenericGetAttr(ob, key); + return true; + + case nameof(PyIdentifier.__dict__): + result = Runtime.PyObject_GenericGetDict(ob); + return true; } if (keyStr == nameof(PyIdentifier.__dict__)) diff --git a/tests/test_method_getattribute.py b/tests/test_method_getattribute.py index 58e755172..57e7a7b27 100644 --- a/tests/test_method_getattribute.py +++ b/tests/test_method_getattribute.py @@ -3,6 +3,14 @@ IBASE = System.Collections.IEnumerable +def test_instance_get_dict(): + class T: + pass + + t = T() + assert isinstance(t.__dict__, dict) + + def test_method_getattribute(): class S1(BASE): def __getattribute__(self, name):