10000 Added IsNone() and GetPyNone() by henon · Pull Request #1137 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Added IsNone() and GetPyNone() #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/runtime/pyobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,10 @@ public bool IsTrue()
return Runtime.PyObject_IsTrue(obj) != 0;
}

/// <summary>
/// Return true if the object is None
/// </summary>
public bool IsNone() => CheckNone(this) == null;

/// <summary>
/// Dir Method
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/// <summary>
/// Check if any Python Exceptions occurred.
/// If any exist throw new PythonException.
Expand Down
0