Skip to content

Property descriptor made visible on the reflected class #1512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/embed_tests/Inspect.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 4 additions & 4 deletions src/runtime/propertyobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Python.Runtime
[Serializable]
internal class PropertyObject : ExtensionType
{
private MaybeMemberInfo<PropertyInfo> info;
internal MaybeMemberInfo<PropertyInfo> info;
private MaybeMethodInfo getter;
private MaybeMethodInfo setter;

Expand Down Expand Up @@ -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
Expand Down