Skip to content

Commit

Permalink
WIP: ´Fix attribute lookup for __set__ only descriptors
Browse files Browse the repository at this point in the history
This makes the first half of the test in test_descr.set_and_no_get pass.
The second part using metaclassses still fail.

I am pretty sure this is not the proper approach, but I don't know what
that would be.

See IronLanguages#1722.
  • Loading branch information
danabr committed Aug 15, 2023
1 parent a1f06f9 commit b77500e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Src/IronPython/Runtime/Binding/MetaUserObject.Members.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public TResult Bind(CodeContext context, string name) {
foundSlot = FindSlot(context, name, sdo, out systemTypeResolution, out extensionMethodResolution);
_extensionMethodRestriction = extensionMethodResolution;

if (sdo.PythonType.HasDictionary && (foundSlot == null || !foundSlot.IsSetDescriptor(context, sdo.PythonType))) {
if (sdo.PythonType.HasDictionary && (foundSlot == null ||
!foundSlot.IsSetDescriptor(context, sdo.PythonType) ||
!foundSlot.IsGetDescriptor(context, sdo.PythonType))) {
MakeDictionaryAccess();
}

Expand Down
4 changes: 4 additions & 0 deletions Src/IronPython/Runtime/Types/PythonTypeSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ internal virtual bool GetAlwaysSucceeds {
}
}

internal virtual bool IsGetDescriptor(CodeContext context, PythonType owner) {
return false;
}

internal virtual bool IsSetDescriptor(CodeContext context, PythonType owner) {
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions Src/IronPython/Runtime/Types/PythonTypeUserDescriptorSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ internal override bool IsSetDescriptor(CodeContext context, PythonType owner) {
return pt.TryResolveSlot(context, "__set__", out _);
}

internal override bool IsGetDescriptor(CodeContext context, PythonType owner) {
PythonType pt = DynamicHelpers.GetPythonType(Value);
if (pt.IsSystemType) return false;
return pt.TryResolveSlot(context, "__get__", out _);
}

internal object Value { get; set; }
}
}

0 comments on commit b77500e

Please sign in to comment.