Disable implicit conversion from PyFloat to .NET integer types by lostmsu · Pull Request #1343 · pythonnet/pythonnet

What does this implement/fix? Explain your changes.

Previously, when a floating point value was passed to .NET parameter of integer type, it would be silently truncated. After this change it would no longer be permitted to pass a floating point value to integer parameter.

Does this close any currently open issues?

#1342

Any other comments?

I removed poorly-behaved PyLong_As* functions, as they would always implicitly convert argument to integer type, which in most cases is undesired behavior. Instead, to avoid roundtrips, PyLong_AsSize_t is used in most cases. The only exception is Int64 which on 32 bit platforms is larger than size_t, so PyLong_AsLongLong function is used after explicit check for PyLong.

Draft because it depends on C# 9, which is not yet ready.

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Updated the CHANGELOG