◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
## Unreleased

### Added
### Changed
### Fixed

- ci: properly exclude job (#2542)

## [3.0.5](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.5) - 2024-12-13
Expand Down
10 changes: 10 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
17 changes: 17 additions & 0 deletions src/runtime/ClassManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
ClassInfo info = GetClassInfo(type, impl);

impl.indexer = info.indexer;
impl.richcompare.Clear();


Expand Down Expand Up @@ -538,6 +539,21 @@ private static ClassInfo GetClassInfo(Type type, ClassBase impl)

ob = new MethodObject(type, name, mlist);
ci.members[name] = ob.AllocObject();
if (mlist.Any(OperatorMethod.IsOperatorMethod))
{
string pyName = OperatorMethod.GetPyMethodName(name);
Expand Down Expand Up @@ -581,6 +597,7 @@ private static ClassInfo GetClassInfo(Type type, ClassBase impl)
private class ClassInfo
{
public Indexer? indexer;
public readonly Dictionary<string, PyObject> members = new();

internal ClassInfo()
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/MethodBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ internal void AddMethod(MethodBase m)
list.Add(m);
}

/// <summary>
/// Given a sequence of MethodInfo and a sequence of types, return the
/// MethodInfo that matches the signature represented by those types.
Expand Down
6 changes: 6 additions & 0 deletions src/runtime/Types/ArrayObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ public static NewReference mp_subscript(BorrowedReference ob, BorrowedReference
/// </summary>
public static int mp_ass_subscript(BorrowedReference ob, BorrowedReference idx, BorrowedReference v)
{
var obj = (CLRObject)GetManagedObject(ob)!;
var items = (Array)obj.inst;
Type itemType = obj.inst.GetType().GetElementType();
Expand Down
42 changes: 40 additions & 2 deletions src/runtime/Types/ClassBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class ClassBase : ManagedType, IDeserializationCallback
[NonSerialized]
internal List<string> dotNetMembers = new();
internal Indexer? indexer;
internal readonly Dictionary<int, MethodObject> richcompare = new();
internal MaybeType type;

Expand Down Expand Up @@ -465,6 +466,11 @@ static int mp_ass_subscript_impl(BorrowedReference ob, BorrowedReference idx, Bo
// with the index arg (method binders expect arg tuples).
NewReference argsTuple = default;

if (!Runtime.PyTuple_Check(idx))
{
argsTuple = Runtime.PyTuple_New(1);
Expand Up @@ -497,13 +503,45 @@ static int mp_ass_subscript_impl(BorrowedReference ob, BorrowedReference idx, Bo
// Add value to argument list
Runtime.PyTuple_SetItem(real.Borrow(), i, v);

cls.indexer.SetItem(ob, real.Borrow());

if (Exceptions.ErrorOccurred())
{
return -1;
}

return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/Types/Indexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ internal NewReference GetItem(BorrowedReference inst, BorrowedReference args)
}


internal void SetItem(BorrowedReference inst, BorrowedReference args)
{
SetterBinder.Invoke(inst, args, null);
}

internal bool NeedsDefaultArgs(BorrowedReference args)
Expand Down
7 changes: 7 additions & 0 deletions src/runtime/Util/ReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public static BindingFlags GetBindingFlags(this PropertyInfo property)
flags |= accessor.IsPublic ? BindingFlags.Public : BindingFlags.NonPublic;
return flags;
}
}
36 changes: 36 additions & 0 deletions tests/test_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,39 @@ def test_public_inherited_overloaded_indexer():

with pytest.raises(TypeError):
ob[[]]
Toggle all file notes Toggle all file annotations