Skip to content

Commit d821b35

Browse files
committed
property descriptor made visible on the reflected class for instance properties
1 parent d3c6942 commit d821b35

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

src/embed_tests/Inspect.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
using NUnit.Framework;
5+
6+
using Python.Runtime;
7+
8+
namespace Python.EmbeddingTest
9+
{
10+
public class Inspect
11+
{
12+
[OneTimeSetUp]
13+
public void SetUp()
14+
{
15+
PythonEngine.Initialize();
16+
}
17+
18+
[OneTimeTearDown]
19+
public void Dispose()
20+
{
21+
PythonEngine.Shutdown();
22+
}
23+
24+
[Test]
25+
public void InstancePropertiesVisibleOnClass()
26+
{
27+
var uri = new Uri("http://example.org").ToPython();
28+
var uriClass = uri.GetPythonType();
29+
var property = uriClass.GetAttr(nameof(Uri.AbsoluteUri));
30+
var pyProp = (PropertyObject)ManagedType.GetManagedObject(property.Reference);
31+
Assert.AreEqual(nameof(Uri.AbsoluteUri), pyProp.info.Value.Name);
32+
}
33+
}
34+
}

src/runtime/propertyobject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Python.Runtime
1111
[Serializable]
1212
internal class PropertyObject : ExtensionType
1313
{
14-
private MaybeMemberInfo<PropertyInfo> info;
14+
internal MaybeMemberInfo<PropertyInfo> info;
1515
private MaybeMethodInfo getter;
1616
private MaybeMethodInfo setter;
1717

@@ -50,9 +50,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
5050
{
5151
if (!getter.IsStatic)
5252
{
53-
Exceptions.SetError(Exceptions.TypeError,
54-
"instance property must be accessed through a class instance");
55-
return IntPtr.Zero;
53+
Runtime.XIncref(ds);
54+
// unbound property
55+
return ds;
5656
}
5757

5858
try

0 commit comments

Comments
 (0)