[编辑]
这已合并到pythonnet:
https://github.com/pythonnet/pythonnet/pull/460
我遇到了可空基元的相同问题-
在我看来Python.NET不支持这些类型。我通过在Python.Runtime.Converter.ToManagedValue()( src
runtime converter.cs)中添加以下代码来解决此问题
if( obType.IsGenericType && obType.GetGenericTypeDefinition() == typeof(Nullable<>) ){ if( value == Runtime.PyNone ) { result = null; return true; } // Set type to underlying type obType = obType.GetGenericArguments()[0];}我将这段代码放在下面
if (value == Runtime.PyNone && !obType.IsValueType) { result = null; return true;}https://github.com/pythonnet/pythonnet/blob/4df6105b98b302029e524c7ce36f7b3cb18f7040/src/runtime/converter.cs#L320



