| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -171,6 +171,28 @@ internal static IntPtr CreateType(ManagedType impl, Type clrType) | |||
| 171 | 171 | Marshal.WriteIntPtr(type, TypeOffset.tp_iter, IntPtr.Zero); | |
| 172 | 172 | } | |
| 173 | 173 | ||
| 174 | + | ||
| 175 | + // Only set mp_subscript and mp_ass_subscript for types with indexers | ||
| 176 | + if (impl is ClassBase cb) | ||
| 177 | + { | ||
| 178 | + if (!(impl is ArrayObject)) | ||
| 179 | + { | ||
| 180 | + if (cb.indexer == null || !cb.indexer.CanGet) | ||
| 181 | + { | ||
| 182 | + Marshal.WriteIntPtr(type, TypeOffset.mp_subscript, IntPtr.Zero); | ||
| 183 | + } | ||
| 184 | + if (cb.indexer == null || !cb.indexer.CanSet) | ||
| 185 | + { | ||
| 186 | + Marshal.WriteIntPtr(type, TypeOffset.mp_ass_subscript, IntPtr.Zero); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + } | ||
| 190 | + else | ||
| 191 | + { | ||
| 192 | + Marshal.WriteIntPtr(type, TypeOffset.mp_subscript, IntPtr.Zero); | ||
| 193 | + Marshal.WriteIntPtr(type, TypeOffset.mp_ass_subscript, IntPtr.Zero); | ||
| 194 | + } | ||
| 195 | + | ||
| 174 | 196 | if (base_ != IntPtr.Zero) | |
| 175 | 197 | { | |
| 176 | 198 | Marshal.WriteIntPtr(type, TypeOffset.tp_base, base_); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1321,16 +1321,14 @@ def test_array_abuse(): | |||
| 1321 | 1321 | with pytest.raises(TypeError): | |
| 1322 | 1322 | Test.PublicArrayTest.__getitem__(0, 0) | |
| 1323 | 1323 | ||
| 1324 | - with pytest.raises(TypeError): | ||
| 1324 | + with pytest.raises(AttributeError): | ||
| 1325 | 1325 | Test.PublicArrayTest.__setitem__(0, 0, 0) | |
| 1326 | 1326 | ||
| 1327 | - with pytest.raises(TypeError): | ||
| 1328 | - desc = Test.PublicArrayTest.__dict__['__getitem__'] | ||
| 1329 | - desc(0, 0) | ||
| 1327 | + with pytest.raises(KeyError): | ||
| 1328 | + Test.PublicArrayTest.__dict__['__getitem__'] | ||
| 1330 | 1329 | ||
| 1331 | - with pytest.raises(TypeError): | ||
| 1332 | - desc = Test.PublicArrayTest.__dict__['__setitem__'] | ||
| 1333 | - desc(0, 0, 0) | ||
| 1330 | + with pytest.raises(KeyError): | ||
| 1331 | + Test.PublicArrayTest.__dict__['__setitem__'] | ||
| 1334 | 1332 | ||
| 1335 | 1333 | ||
| 1336 | 1334 | def test_iterator_to_array(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,7 @@ def test_internal_indexer(): | |||
| 42 | 42 | with pytest.raises(TypeError): | |
| 43 | 43 | Test.InternalIndexerTest.__getitem__(ob, 0) | |
| 44 | 44 | ||
| 45 | - with pytest.raises(TypeError): | ||
| 45 | + with pytest.raises(AttributeError): | ||
| 46 | 46 | ob.__getitem__(0) | |
| 47 | 47 | ||
| 48 | 48 | ||
@@ -56,7 +56,7 @@ def test_private_indexer(): | |||
| 56 | 56 | with pytest.raises(TypeError): | |
| 57 | 57 | Test.PrivateIndexerTest.__getitem__(ob, 0) | |
| 58 | 58 | ||
| 59 | - with pytest.raises(TypeError): | ||
| 59 | + with pytest.raises(AttributeError): | ||
| 60 | 60 | ob.__getitem__(0) | |
| 61 | 61 | ||
| 62 | 62 | ||
@@ -603,3 +603,14 @@ def test_indexer_accessed_through_interface(): | |||
| 603 | 603 | d = IDictionary[str, str](Dictionary[str, str]()) | |
| 604 | 604 | d["one"] = "1" | |
| 605 | 605 | assert d["one"] == "1" | |
| 606 | + | ||
| 607 | + | ||
| 608 | + def test_using_indexer_on_object_without_indexer(): | ||
| 609 | + """Test using subscript syntax on an object an without indexer raises""" | ||
| 610 | + from System import Object | ||
| 611 | + o = Object() | ||
| 612 | + with pytest.raises(TypeError) | ||
| 613 | + o[0] | ||
| 614 | + | ||
| 615 | + with pytest.raises(TypeError) | ||
| 616 | + o[0] = 1 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments