Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a31c590

Browse files
authored
Merge branch 'master' into missing_func
2 parents 6c27e84 + cc48374 commit a31c590

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Christopher Pow ([@christopherpow](https://github.com/christopherpow))
2020
- Daniel Fernandez ([@fdanny](https://github.com/fdanny))
2121
- Daniel Santana ([@dgsantana](https://github.com/dgsantana))
22+
- Dave Hirschfeld ([@dhirschfeld](https://github.com/dhirschfeld))
2223
- David Lechner ([@dlech](https://github.com/dlech))
2324
- Dmitriy Se ([@dmitriyse](https://github.com/dmitriyse))
2425
- He-chien Tsai ([@t3476](https://github.com/t3476))

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1010
### Added
1111
- Added clr.GetClrType (#432)(#433)
1212
- Added `Foo` feature
13+
- Allowed passing None for nullable args (#460)
1314

1415
### Changed
1516

src/runtime/converter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,17 @@ internal static bool ToManagedValue(IntPtr value, Type obType,
318318
return true;
319319
}
320320

321+
if (obType.IsGenericType && obType.GetGenericTypeDefinition() == typeof(Nullable<>))
322+
{
323+
if( value == Runtime.PyNone )
324+
{
325+
result = null;
326+
return true;
327+
}
328+
// Set type to underlying type
329+
obType = obType.GetGenericArguments()[0];
330+
}
331+
321332
if (obType.IsArray)
322333
{
323334
return ToArray(value, obType, out result, setError);

src/testing/conversiontest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ public ConversionTest()
3232

3333
public byte[] ByteArrayField;
3434
public sbyte[] SByteArrayField;
35+
36+
public T? Echo<T>(T? arg) where T: struct {
37+
return arg;
38+
}
39+
3540
}
3641

42+
3743

3844
public interface ISpam
3945
{

src/tests/test_conversion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ def test_enum_conversion():
641641

642642
def test_null_conversion():
643643
"""Test null conversion."""
644+
import System
645+
644646
ob = ConversionTest()
645647

646648
ob.StringField = None
@@ -652,6 +654,10 @@ def test_null_conversion():
652654
ob.SpamField = None
653655
assert ob.SpamField is None
654656

657+
pi = 22/7
658+
assert ob.Echo[System.Double](pi) == pi
659+
assert ob.Echo[System.DateTime](None) is None
660+
655661
# Primitive types and enums should not be set to null.
656662

657663
with pytest.raises(TypeError):

0 commit comments

Comments
 (0)