FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Disable implicit conversion from PyFloat to uint64 (#1362) · AlgoTradingSrc/pythonnet@7e7cbca · GitHub

Repository navigation

Commit 7e7cbca

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

2 files changed

Lines changed: 6 additions & 12 deletions

File tree

‎src/runtime/converter.cs‎

Lines changed: 2 additions & 11 deletions
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‎

Lines changed: 4 additions & 1 deletion
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)

Back | FazBrowse Home | New Git URL