Skip to content

Commit 7e7cbca

Browse files
authored
Disable implicit conversion from PyFloat to uint64 (#1362)
1 parent 5fd77b1 commit 7e7cbca

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/runtime/converter.cs

+2-11
Original file line numberDiff line numberDiff line change
@@ -698,19 +698,10 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
698698

699699
case TypeCode.UInt64:
700700
{
701-
op = value;
702-
if (Runtime.PyObject_TYPE(value) != Runtime.PyLongType)
703-
{
704-
op = Runtime.PyNumber_Long(value);
705-
if (op == IntPtr.Zero)
706-
{
707-
goto convert_error;
708-
}
709-
}
710-
ulong num = Runtime.PyLong_AsUnsignedLongLong(op);
701+
ulong num = Runtime.PyLong_AsUnsignedLongLong(value);
711702
if (num == ulong.MaxValue && Exceptions.ErrorOccurred())
712703
{
713-
goto overflow;
704+
goto convert_error;
714705
}
715706
result = num;
716707
return true;

src/tests/test_conversion.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,10 @@ def test_uint64_conversion():
382382
ob.UInt64Field = System.UInt64(0)
383383
assert ob.UInt64Field == 0
384384

385-
with pytest.raises(ValueError):
385+
with pytest.raises(TypeError):
386+
ConversionTest().UInt64Field = 0.5
387+
388+
with pytest.raises(TypeError):
386389
ConversionTest().UInt64Field = "spam"
387390

388391
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)