Skip to content

Commit e92d24b

Browse files
jhonabreulclaude
andcommitted
Inspect property descriptor via type __dict__
Accessing an instance property through the class object now intentionally raises (it must be accessed through an instance), so InstancePropertiesVisibleOnClass can no longer use GetAttr to retrieve the descriptor. Read it from the type's __dict__ instead, which bypasses the descriptor protocol. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d55dcaa commit e92d24b

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/embed_tests/Inspect.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public void InstancePropertiesVisibleOnClass()
2626
{
2727
var uri = new Uri("http://example.org").ToPython();
2828
var uriClass = uri.GetPythonType();
29-
var property = uriClass.GetAttr(nameof(Uri.AbsoluteUri));
30-
var pyProp = (PropertyObject)ManagedType.GetManagedObject(property.Reference);
29+
// Accessing an instance property through the class object invokes the
30+
// descriptor protocol, which intentionally raises (an instance property
31+
// must be accessed through an instance). To inspect the descriptor
32+
// itself, read it from the type's __dict__, which bypasses __get__.
33+
using var classDict = uriClass.GetAttr("__dict__");
34+
var property = classDict.GetItem(nameof(Uri.AbsoluteUri)); var pyProp = (PropertyObject)ManagedType.GetManagedObject(property.Reference);
3135
Assert.AreEqual(nameof(Uri.AbsoluteUri), pyProp.info.Value.Name);
3236
}
3337

0 commit comments

Comments
 (0)