Skip to content

Commit 4cf73e7

Browse files
committed
Disable implicit conversions, that might lose information:
PyInt -> int32 .NET arrays and collections -> Python list (due to mutability)
1 parent f64194c commit 4cf73e7

File tree

6 files changed

+111
-100
lines changed

6 files changed

+111
-100
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2020
- .NET collection types now implement standard Python collection interfaces from `collections.abc`.
2121
See [Mixins/collections.py](src/runtime/Mixins/collections.py).
2222
- .NET arrays implement Python buffer protocol
23+
- Python.NET will correctly resolve .NET methods, that accept `PyList`, `PyInt`,
24+
and other `PyObject` derived types when called from Python.
2325

2426

2527
### Changed
@@ -51,13 +53,20 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
5153
- Sign Runtime DLL with a strong name
5254
- Implement loading through `clr_loader` instead of the included `ClrModule`, enables
5355
support for .NET Core
54-
- .NET and Python exceptions are preserved when crossing Python/.NET boundary
56+
- BREAKING: .NET and Python exceptions are preserved when crossing Python/.NET boundary
5557
- BREAKING: custom encoders are no longer called for instances of `System.Type`
5658
- `PythonException.Restore` no longer clears `PythonException` instance.
5759
- Replaced the old `__import__` hook hack with a PEP302-style Meta Path Loader
5860
- BREAKING: Names of .NET types (e.g. `str(__class__)`) changed to better support generic types
5961
- BREAKING: overload resolution will no longer prefer basic types. Instead, first matching overload will
6062
be chosen.
63+
- BREAKING: .NET collections and arrays are no longer automatically converted to
64+
Python collections. Instead, they implement standard Python
65+
collection interfaces from `collections.abc`.
66+
See [Mixins/collections.py](src/runtime/Mixins/collections.py).
67+
- BREAKING: When trying to convert Python `int` to `System.Object`, result will
68+
be of type `PyInt` instead of `System.Int32` due to possible loss of information.
69+
Python `float` will continue to be converted to `System.Double`.
6170

6271
### Fixed
6372

src/embed_tests/TestConverter.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,25 @@ public void ConvertOverflow()
116116
}
117117
}
118118

119+
[Test]
120+
public void ToNullable()
121+
{
122+
const int Const = 42;
123+
var i = new PyInt(Const);
124+
var ni = i.As<int?>();
125+
Assert.AreEqual(Const, ni);
126+
}
127+
128+
[Test]
129+
public void ToPyList()
130+
{
131+
var list = new PyList();
132+
list.Append("hello".ToPython());
133+
list.Append("world".ToPython());
134+
var back = list.ToPython().As<PyList>();
135+
Assert.AreEqual(list.Length(), back.Length());
136+
}
137+
119138
[Test]
120139
public void RawListProxy()
121140
{

0 commit comments

Comments
 (0)