diff --git a/AUTHORS.md b/AUTHORS.md index b0d1f0c91..19cd4f5ed 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -45,6 +45,7 @@ - Luke Stratman ([@lstratman](https://github.com/lstratman)) - Konstantin Posudevskiy ([@konstantin-posudevskiy](https://github.com/konstantin-posudevskiy)) - Matthias Dittrich ([@matthid](https://github.com/matthid)) +- Meinrad Recheis ([@henon](https://github.com/henon)) - Mohamed Koubaa ([@koubaa](https://github.com/koubaa)) - Patrick Stewart ([@patstew](https://github.com/patstew)) - Raphael Nestler ([@rnestler](https://github.com/rnestler)) diff --git a/CHANGELOG.md b/CHANGELOG.md index f754cbc4e..13baf557e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. - Added support for Jetson Nano. - Added support for __len__ for .NET classes that implement ICollection - Added PythonException.Format method to format exceptions the same as traceback.format_exception +- Added Runtime.None to be able to pass None as parameter into Python from .NET +- Added PyObject.IsNone() to check if a Python object is None in .NET. ### Changed diff --git a/src/runtime/pyobject.cs b/src/runtime/pyobject.cs index 96968e678..491c62e30 100644 --- a/src/runtime/pyobject.cs +++ b/src/runtime/pyobject.cs @@ -979,6 +979,10 @@ public bool IsTrue() return Runtime.PyObject_IsTrue(obj) != 0; } + /// + /// Return true if the object is None + /// + public bool IsNone() => CheckNone(this) == null; /// /// Dir Method diff --git a/src/runtime/runtime.cs b/src/runtime/runtime.cs index 3d1fe2d39..2e06c9cba 100644 --- a/src/runtime/runtime.cs +++ b/src/runtime/runtime.cs @@ -473,6 +473,16 @@ private static void ResetPyMembers() internal static IntPtr PyNone; internal static IntPtr Error; + public static PyObject None + { + get + { + var none = Runtime.PyNone; + Runtime.XIncref(none); + return new PyObject(none); + } + } + /// /// Check if any Python Exceptions occurred. /// If any exist throw new PythonException.