🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 2 additions & 6 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,16 +701,12 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
op = value;
if (Runtime.PyObject_TYPE(value) != Runtime.PyLongType)
{
op = Runtime.PyNumber_Long(value);
if (op == IntPtr.Zero)
{
goto convert_error;
}
goto type_error;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be skipped alltogether. https://docs.python.org/3.8/c-api/long.html#c.PyLong_AsUnsignedLongLong already checks the type.

}
ulong num = Runtime.PyLong_AsUnsignedLongLong(op);
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