Skip to content

Disable implicit conversion from PyFloat to uint64 #1362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -698,19 +698,10 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo

case TypeCode.UInt64:
{
op = value;
if (Runtime.PyObject_TYPE(value) != Runtime.PyLongType)
{
op = Runtime.PyNumber_Long(value);
if (op == IntPtr.Zero)
{
goto convert_error;
}
}
ulong num = Runtime.PyLong_AsUnsignedLongLong(op);
ulong num = Runtime.PyLong_AsUnsignedLongLong(value);
if (num == ulong.MaxValue && Exceptions.ErrorOccurred())
{
goto overflow;
goto convert_error;
}
result = num;
return true;
Expand Down
5 changes: 4 additions & 1 deletion src/tests/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ def test_uint64_conversion():
ob.UInt64Field = System.UInt64(0)
assert ob.UInt64Field == 0

with pytest.raises(ValueError):
with pytest.raises(TypeError):
ConversionTest().UInt64Field = 0.5

with pytest.raises(TypeError):
ConversionTest().UInt64Field = "spam"

with pytest.raises(TypeError):
Expand Down