| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,7 @@ interface ITypeOffsets | |||
| 31 | 31 | int nb_invert { get; } | |
| 32 | 32 | int nb_inplace_add { get; } | |
| 33 | 33 | int nb_inplace_subtract { get; } | |
| 34 | + int nb_index { get; } | ||
| 34 | 35 | int ob_size { get; } | |
| 35 | 36 | int ob_type { get; } | |
| 36 | 37 | int qualname { get; } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,7 @@ static partial class TypeOffset | |||
| 38 | 38 | internal static int nb_invert { get; private set; } | |
| 39 | 39 | internal static int nb_inplace_add { get; private set; } | |
| 40 | 40 | internal static int nb_inplace_subtract { get; private set; } | |
| 41 | + internal static int nb_index { get; private set; } | ||
| 41 | 42 | internal static int ob_size { get; private set; } | |
| 42 | 43 | internal static int ob_type { get; private set; } | |
| 43 | 44 | internal static int qualname { get; private set; } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -604,17 +604,20 @@ public virtual void InitializeSlots(BorrowedReference pyType, SlotsHolder slotsH | |||
| 604 | 604 | case TypeCode.Int32: | |
| 605 | 605 | case TypeCode.Int64: | |
| 606 | 606 | TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_int, new Interop.B_N(DoConvertInt), slotsHolder); | |
| 607 | + TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_index, new Interop.B_N(DoConvertInt), slotsHolder); | ||
| 607 | 608 | TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_float, new Interop.B_N(DoConvertFloat), slotsHolder); | |
| 608 | 609 | break; | |
| 609 | 610 | case TypeCode.Byte: | |
| 610 | 611 | case TypeCode.UInt16: | |
| 611 | 612 | case TypeCode.UInt32: | |
| 612 | 613 | case TypeCode.UInt64: | |
| 613 | 614 | TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_int, new Interop.B_N(DoConvertUInt), slotsHolder); | |
| 615 | + TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_index, new Interop.B_N(DoConvertUInt), slotsHolder); | ||
| 614 | 616 | TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_float, new Interop.B_N(DoConvertFloat), slotsHolder); | |
| 615 | 617 | break; | |
| 616 | 618 | case TypeCode.Double: | |
| 617 | 619 | case TypeCode.Single: | |
| 620 | + TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_int, new Interop.B_N(DoConvertInt), slotsHolder); | ||
| 618 | 621 | TypeManager.InitializeSlotIfEmpty(pyType, TypeOffset.nb_float, new Interop.B_N(DoConvertFloat), slotsHolder); | |
| 619 | 622 | break; | |
| 620 | 623 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,7 @@ static OperatorMethod() | |||
| 54 | 54 | ||
| 55 | 55 | ["__int__"] = new SlotDefinition("__int__", TypeOffset.nb_int), | |
| 56 | 56 | ["__float__"] = new SlotDefinition("__float__", TypeOffset.nb_float), | |
| 57 | + ["__index__"] = new SlotDefinition("__index__", TypeOffset.nb_index), | ||
| 57 | 58 | }; | |
| 58 | 59 | ComparisonOpMap = new Dictionary<string, string> | |
| 59 | 60 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,10 +82,14 @@ internal static class EnumOps<T> where T : Enum | |||
| 82 | 82 | { | |
| 83 | 83 | [ForbidPythonThreads] | |
| 84 | 84 | #pragma warning disable IDE1006 // Naming Styles - must match Python | |
| 85 | - public static PyInt __int__(T value) | ||
| 85 | + public static PyInt __index__(T value) | ||
| 86 | 86 | #pragma warning restore IDE1006 // Naming Styles | |
| 87 | 87 | => typeof(T).GetEnumUnderlyingType() == typeof(UInt64) | |
| 88 | 88 | ? new PyInt(Convert.ToUInt64(value)) | |
| 89 | 89 | : new PyInt(Convert.ToInt64(value)); | |
| 90 | + [ForbidPythonThreads] | ||
| 91 | + #pragma warning disable IDE1006 // Naming Styles - must match Python | ||
| 92 | + public static PyInt __int__(T value) => __index__(value); | ||
| 93 | + #pragma warning restore IDE1006 // Naming Styles | ||
| 90 | 94 | } | |
| 91 | 95 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -721,6 +721,7 @@ def test_intptr_construction(): | |||
| 721 | 721 | UIntPtr(v) | |
| 722 | 722 | ||
| 723 | 723 | def test_explicit_conversion(): | |
| 724 | + from operator import index | ||
| 724 | 725 | from System import ( | |
| 725 | 726 | Int64, UInt64, Int32, UInt32, Int16, UInt16, Byte, SByte, Boolean | |
| 726 | 727 | ) | |
@@ -730,18 +731,24 @@ def test_explicit_conversion(): | |||
| 730 | 731 | assert int(Boolean(True)) == 1 | |
| 731 | 732 | ||
| 732 | 733 | for t in [UInt64, UInt32, UInt16, Byte]: | |
| 734 | + assert index(t(127)) == 127 | ||
| 733 | 735 | assert int(t(127)) == 127 | |
| 734 | 736 | assert float(t(127)) == 127.0 | |
| 735 | 737 | ||
| 736 | 738 | for t in [Int64, Int32, Int16, SByte]: | |
| 739 | + assert index(t(127)) == 127 | ||
| 740 | + assert index(t(-127)) == -127 | ||
| 737 | 741 | assert int(t(127)) == 127 | |
| 738 | 742 | assert int(t(-127)) == -127 | |
| 739 | 743 | assert float(t(127)) == 127.0 | |
| 740 | 744 | assert float(t(-127)) == -127.0 | |
| 741 | 745 | ||
| 742 | - assert int(Int64.MaxValue) == 2**63 - 1 | ||
| 743 | - assert int(Int64.MinValue) == -2**63 | ||
| 744 | - assert int(UInt64.MaxValue) == 2**64 - 1 | ||
| 746 | + assert int(Int64(Int64.MaxValue)) == 2**63 - 1 | ||
| 747 | + assert int(Int64(Int64.MinValue)) == -2**63 | ||
| 748 | + assert int(UInt64(UInt64.MaxValue)) == 2**64 - 1 | ||
| 745 | 749 | ||
| 746 | 750 | for t in [Single, Double]: | |
| 747 | 751 | assert float(t(0.125)) == 0.125 | |
| 752 | + assert int(t(123.4)) == 123 | ||
| 753 | + with pytest.raises(TypeError): | ||
| 754 | + index(t(123.4)) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments