From 5a23349405de1ebff6ff7bf5ce57a59b85eda840 Mon Sep 17 00:00:00 2001 From: Victor Milovanov Date: Fri, 23 Oct 2020 12:08:03 -0700 Subject: [PATCH] property descriptor made visible on the reflected class for instance properties --- src/embed_tests/Inspect.cs | 34 ++++++++++++++++++++++++++++++++++ src/runtime/propertyobject.cs | 8 ++++---- 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 src/embed_tests/Inspect.cs diff --git a/src/embed_tests/Inspect.cs b/src/embed_tests/Inspect.cs new file mode 100644 index 000000000..823a0169a --- /dev/null +++ b/src/embed_tests/Inspect.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; + +using NUnit.Framework; + +using Python.Runtime; + +namespace Python.EmbeddingTest +{ + public class Inspect + { + [OneTimeSetUp] + public void SetUp() + { + PythonEngine.Initialize(); + } + + [OneTimeTearDown] + public void Dispose() + { + PythonEngine.Shutdown(); + } + + [Test] + public void InstancePropertiesVisibleOnClass() + { + var uri = new Uri("http://example.org").ToPython(); + var uriClass = uri.GetPythonType(); + var property = uriClass.GetAttr(nameof(Uri.AbsoluteUri)); + var pyProp = (PropertyObject)ManagedType.GetManagedObject(property.Reference); + Assert.AreEqual(nameof(Uri.AbsoluteUri), pyProp.info.Value.Name); + } + } +} diff --git a/src/runtime/propertyobject.cs b/src/runtime/propertyobject.cs index 20061b358..3cef84a09 100644 --- a/src/runtime/propertyobject.cs +++ b/src/runtime/propertyobject.cs @@ -11,7 +11,7 @@ namespace Python.Runtime [Serializable] internal class PropertyObject : ExtensionType { - private MaybeMemberInfo info; + internal MaybeMemberInfo info; private MaybeMethodInfo getter; private MaybeMethodInfo setter; @@ -50,9 +50,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp) { if (!getter.IsStatic) { - Exceptions.SetError(Exceptions.TypeError, - "instance property must be accessed through a class instance"); - return IntPtr.Zero; + Runtime.XIncref(ds); + // unbound property + return ds; } try