8000 property descriptor made visible on the reflected class for instance … · losttech/pythonnet@8b74b31 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8b74b31

Browse files
committed
property descriptor made visible on the reflected class for instance properties
1 parent dfe85da commit 8b74b31

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/embed_tests/Inspect.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public void BoundMethodsAreInspectable() {
2626
}
2727
}
2828

29+
[Test]
30+
public void InstancePropertiesVisibleOnClass() {
31+
var uri = new Uri("http://example.org").ToPython();
32+
var uriClass = uri.GetPythonType();
33+
var property = uriClass.GetAttr(nameof(Uri.AbsoluteUri));
34+
var pyProp = ManagedType.GetManagedObject<PropertyObject>(property.Reference);
35+
Assert.AreEqual(nameof(Uri.AbsoluteUri), pyProp.info.Name);
36+
}
37+
2938
class Class {
3039
public void Method(int a, int b = 10) { }
3140
public void Method(int a, object b) { }

src/runtime/propertyobject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Python.Runtime
99
/// </summary>
1010
internal class PropertyObject : ExtensionType
1111
{
12-
private PropertyInfo info;
12+
internal PropertyInfo info;
1313
private MethodInfo getter;
1414
private MethodInfo setter;
1515

@@ -44,9 +44,9 @@ public static IntPtr tp_descr_get(IntPtr ds, IntPtr ob, IntPtr tp)
4444
{
4545
if (!getter.IsStatic)
4646
{
47-
Exceptions.SetError(Exceptions.TypeError,
48-
"instance property must be accessed through a class instance");
49-
return IntPtr.Zero;
47+
Runtime.XIncref(ds);
48+
// unbound property
49+
return ds;
5050
}
5151

5252
try

0 commit comments

Comments
 (0)
0