From 751542695fba0b62c4385745ec1a6abedc43e5c0 Mon Sep 17 00:00:00 2001 From: eirannejad Date: Thu, 14 Nov 2024 08:25:48 -0800 Subject: [PATCH] Fixed dict access attrib error --- src/runtime/Types/ReflectedClrType.cs | 11 ++++++++--- tests/test_method_getattribute.py | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/runtime/Types/ReflectedClrType.cs b/src/runtime/Types/ReflectedClrType.cs index 61db3633d..5ad9fa61d 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; } return false; 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):