pythonnet v3.0.0 Release Notes
Release Date: 2022-09-29 // about 2 years ago-
โ Added
- Ability to instantiate new .NET arrays using
Array[T](dim1, dim2, ...)
syntax - ๐ Python operator method will call C# operator method for supported binary and unary operators ([#1324][p1324]).
- Add GetPythonThreadID and Interrupt methods in PythonEngine
- Ability to implement delegates with
ref
andout
parameters in Python, by returning the modified parameter values in a tuple. ([#1355][i1355]) - Ability to override .NET methods that have
out
orref
in Python by returning the modified parameter values in a tuple. ([#1481][i1481]) -
PyType
- a wrapper for Python type objects, that also permits creating new heap types fromTypeSpec
- ๐ป Improved exception handling:
- exceptions can now be converted with codecs
-
InnerException
and__cause__
are propagated properly
-
__name__
and__signature__
to reflected .NET methods - .NET collection types now implement standard Python collection interfaces from
collections.abc
. ๐ See [Mixins/collections.py](src/runtime/Mixins/collections.py). - you can cast objects to generic .NET interfaces without specifying generic arguments as long as there is no ambiguity.
- .NET arrays implement Python buffer protocol
- Python integer interoperability with
System.Numerics.BigInteger
- Python.NET will correctly resolve .NET methods, that accept
PyList
,PyInt
, and otherPyObject
derived types when called from Python. - .NET classes, that have
__call__
method are callable from Python -
PyIterable
type, that wraps any iterable object in Python - ๐
PythonEngine
properties for supported Python versions:MinSupportedVersion
,MaxSupportedVersion
, andIsSupportedVersion
- ๐ง The runtime that is loaded on
import clr
can now be configured via environment variables
๐ Changed
- ๐ Drop support for Python 2, 3.4, 3.5, and 3.6
-
wchar_t
size akaRuntime.UCS
is now determined at runtime -
clr.AddReference
may now throw errors besidesFileNotFoundException
, that provide more details about the cause of the failure -
clr.AddReference
no longer adds ".dll" implicitly -
PyIter(PyObject)
constructor replaced with staticPyIter.GetIter(PyObject)
method - Python runtime can no longer be shut down if the Python error indicator is set, as it would have unpredictable behavior
- BREAKING: Return values from .NET methods that return an interface are now automatically
wrapped in that interface. This is a breaking change for users that rely on being
able to access members that are part of the implementation class, but not the
interface. Use the new
__implementation__
or__raw_implementation__
properties to if you need to "downcast" to the implementation class. - BREAKING:
==
and!=
operators onPyObject
instances now use Python comparison (previously was equivalent toobject.ReferenceEquals(,)
) - BREAKING: Parameters marked with
ParameterAttributes.Out
are no longer returned in addition to the regular method return value (unless they are passed withref
orout
keyword). - ๐ BREAKING: Drop support for the long-deprecated CLR.* prefix.
-
PyObject
now implementsIEnumerable<PyObject>
in addition toIEnumerable
- floating point values passed from Python are no longer silently truncated when .NET expects an integer [#1342][i1342]
- More specific error messages for method argument mismatch
- members of
PyObject
inherited fromSystem.Object and
DynamicObject` now autoacquire GIL - BREAKING: when inheriting from .NET types in Python if you override
__init__
you must explicitly call base constructor usingsuper().__init__(.....)
. Not doing so will lead to undefined behavior. - BREAKING: most
PyScope
methods will never returnnull
. Instead,PyObject
None
will be returned. - BREAKING:
PyScope
was renamed toPyModule
- BREAKING: Methods with
ref
orout
parameters and void return type return a tuple of only theref
andout
parameters. - BREAKING: to call Python from .NET
Runtime.PythonDLL
property must be set to Python DLL name or the DLL must be loaded in advance. This must be done before calling any other Python.NET functions. - ๐ BREAKING:
PyObject.Length()
now raises aPythonException
when object does not support a concept of length. - BREAKING: disabled implicit conversion from C# enums to Python
int
and back. One must now either use enum members (e.g.MyEnum.Option
), or use enum constructor (e.g.MyEnum(42)
orMyEnum(42, True)
whenMyEnum
does not have a member with value 42). - BREAKING: disabled implicit conversion from Python objects implementing sequence protocol to
.NET arrays when the target .NET type is
System.Object
. The conversion is still attempted when the target type is aSystem.Array
. - Sign Runtime DLL with a strong name
- Implement loading through
clr_loader
instead of the includedClrModule
, enables support for .NET Core - BREAKING: .NET and Python exceptions are preserved when crossing Python/.NET boundary
- BREAKING: custom encoders are no longer called for instances of
System.Type
- โช
PythonException.Restore
no longer clearsPythonException
instance. - Replaced the old
__import__
hook hack with a PEP302-style Meta Path Loader - BREAKING: Names of .NET types (e.g.
str(__class__)
) changed to better support generic types - BREAKING: overload resolution will no longer prefer basic types. Instead, first matching overload will be chosen.
- BREAKING: acquiring GIL using
Py.GIL
no longer forcesPythonEngine
to initialize - BREAKING:
Exec
andEval
fromPythonEngine
no longer accept raw pointers. - BREAKING: .NET collections and arrays are no longer automatically converted to
Python collections. Instead, they implement standard Python
collection interfaces from
collections.abc
. ๐ See [Mixins/collections.py](src/runtime/Mixins/collections.py). - BREAKING: When trying to convert Python
int
toSystem.Object
, result will be of typePyInt
instead ofSystem.Int32
due to possible loss of information. Pythonfloat
will continue to be converted toSystem.Double
. - BREAKING: Python.NET will no longer implicitly convert types like
numpy.float64
, that implement__float__
toSystem.Single
andSystem.Double
. An explicit conversion is required on Python or .NET side. - BREAKING:
PyObject.GetHashCode
can fail. - BREAKING: Python.NET will no longer implicitly convert any Python object to
System.Boolean
. - 0๏ธโฃ BREAKING:
PyObject.GetAttr(name, default)
now only ignoresAttributeError
(previously ignored all exceptions). - BREAKING:
PyObject
no longer implementsIEnumerable<PyObject>
. Instead,PyIterable
does that. - BREAKING:
IPyObjectDecoder.CanDecode
objectType
parameter type changed fromPyObject
toPyType
๐ Fixed
- Fix incorrect dereference of wrapper object in
tp_repr
, which may result in a program crash - ๐ Fixed parameterless .NET constructor being silently called when a matching constructor overload is not found ([#238][i238])
- Fix incorrect dereference in params array handling
- ๐ Fixes issue with function resolution when calling overloaded function with keyword arguments from python ([#1097][i1097])
- Fix
object[]
parameters taking precedence when should not in overload resolution - ๐ Fixed a bug where all .NET class instances were considered Iterable
- Fix incorrect choice of method to invoke when using keyword arguments.
- Fix non-delegate types incorrectly appearing as callable.
- Indexers can now be used with interface objects
- ๐ Fixed a bug where indexers could not be used if they were inherited
- Made it possible to use
__len__
also onICollection<>
interface objects - ๐ Fixed issue when calling PythonException.Format where another exception would be raise for unnormalized exceptions
- Made it possible to call
ToString
,GetHashCode
, andGetType
on inteface objects - ๐ Fixed objects returned by enumerating
PyObject
being disposed too soon - Incorrectly using a non-generic type with type parameters now produces a helpful Python error instead of throwing NullReferenceException
- ๐ฉ
import
may now raise errors with more detail than "No module named X" - ๐ป Exception stacktraces on
PythonException.StackTrace
are now properly formatted - Providing an invalid type parameter to a generic type or method produces a helpful Python error
- Empty parameter names (as can be generated from F#) do not cause crashes
- Unicode strings with surrogates were truncated when converting from Python
- ๐
Reload
mode now supports generic methods (previously Python would stop seeing them after reload) - ๐ Temporarily fixed issue resolving method overload when method signature has
out
parameters ([#1672](i1672)) - 0๏ธโฃ Decimal default parameters are now correctly taken into account
โ Removed
- ๐
ShutdownMode
has been removed. The only shutdown mode supported now is an equivalent ofShutdownMode.Reload
. There is no need to specify it. - implicit assembly loading (you have to explicitly
clr.AddReference
before doing import) - ๐ป messages in
PythonException
no longer start with exception type -
PyScopeManager
,PyScopeException
,PyScope
(usePyModule
instead) - ๐ support for .NET Framework 4.0-4.6; Mono before 5.4. Python.NET now requires .NET Standard 2.0 ๐ (see the matrix)
- Ability to instantiate new .NET arrays using