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

Skip to content

Commit 48b18a4

Browse files
authored
Merge branch 'master' into master
2 parents 8bc01ad + c18285f commit 48b18a4

9 files changed

Lines changed: 37 additions & 7 deletions

File tree

AUTHORS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
- David Lechner ([@dlech](https://github.com/dlech))
2424
- Dmitriy Se ([@dmitriyse](https://github.com/dmitriyse))
2525
- He-chien Tsai ([@t3476](https://github.com/t3476))
26-
- Jeff Reback ([@jreback](https://github.com/jreback))
26+
-   Ivan Cronyn ([@cronan](https://github.com/cronan))
27+
-   Jeff Reback ([@jreback](https://github.com/jreback))
2728
- Joe Frayne ([@jfrayne](https://github.com/jfrayne))
2829
- John Burnett ([@johnburnett](https://github.com/johnburnett))
2930
- Luke Stratman ([@lstratman](https://github.com/lstratman))

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2828
- Fixed conversion of 'float' and 'double' values (#486)
2929
- Fixed 'clrmethod' for python 2 (#492)
3030
- Fixed double calling of constructor when deriving from .NET class (#495)
31+
- Fixed `clr.GetClrType` when iterating over `System` members (#607)
3132

3233

3334
## [2.3.0][] - 2017-03-11

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ from System.Windows.Forms import Form
4444
a `using (Py.GIL()) {/* Your code here */}` block.
4545
- Import python modules using `dynamic mod = Py.Import("mod")`,
4646
then you can call functions as normal, eg `mod.func(args)`.
47-
- Use `mod.func(args, Py.kw("keywordargname", keywordargvalue))` or `mod.func(args, keywordargname=keywordargvalue)`
47+
- Use `mod.func(args, Py.kw("keywordargname", keywordargvalue))` or `mod.func(args, keywordargname: keywordargvalue)`
4848
to apply keyword arguments.
4949
- All python objects should be declared as `dynamic` type.
5050
- Mathematical operations involving python and literal/managed types must

src/embed_tests/TestExample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void TestReadme()
4747
dynamic b = np.array(new List<float> { 6, 5, 4 }, Py.kw("dtype", np.int32));
4848
Assert.AreEqual("int32", b.dtype.ToString());
4949

50-
Assert.AreEqual("[ 6. 10. 12.]", (a * b).ToString());
50+
Assert.AreEqual("[ 6. 10. 12.]", (a * b).ToString().Replace(" ", " "));
5151
}
5252
}
5353
}

src/embed_tests/TestPythonException.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,19 @@ public void TestNoError()
4040
var e = new PythonException(); // There is no PyErr to fetch
4141
Assert.AreEqual("", e.Message);
4242
}
43+
44+
[Test]
45+
public void TestPythonErrorTypeName()
46+
{
47+
try
48+
{
49+
var module = PythonEngine.ImportModule("really____unknown___module");
50+
Assert.Fail("Unknown module should not be loaded");
51+
}
52+
catch (PythonException ex)
53+
{
54+
Assert.That(ex.PythonTypeName, Is.EqualTo("ModuleNotFoundError").Or.EqualTo("ImportError"));
55+
}
56+
}
4357
}
4458
}

src/embed_tests/dynamic.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void PassObjectInPython()
103103
Assert.AreEqual(sys.testattr3.ToString(), "True");
104104

105105
// Compare in .NET
106-
Assert.AreEqual(sys.testattr1, sys.testattr2);
106+
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
107107
}
108108

109109
/// <summary>
@@ -125,7 +125,7 @@ public void PassPyObjectInNet()
125125
Assert.AreEqual(sys.testattr3.ToString(), "True");
126126

127127
// Compare in .NET
128-
Assert.AreEqual(sys.testattr1, sys.testattr2);
128+
Assert.IsTrue(sys.testattr1.Equals(sys.testattr2));
129129
}
130130
}
131131
}

src/runtime/managedtype.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Runtime.InteropServices;
33

44
namespace Python.Runtime
@@ -34,6 +34,10 @@ internal static ManagedType GetManagedObject(IntPtr ob)
3434
IntPtr op = tp == ob
3535
? Marshal.ReadIntPtr(tp, TypeOffset.magic())
3636
: Marshal.ReadIntPtr(ob, ObjectOffset.magic(ob));
37+
if (op == IntPtr.Zero)
38+
{
39+
return null;
40+
}
3741
var gc = (GCHandle)op;
3842
return (ManagedType)gc.Target;
3943
}

src/runtime/pyobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Python.Runtime
1212
/// PY3: https://docs.python.org/3/c-api/object.html
1313
/// for details.
1414
/// </summary>
15-
public class PyObject : DynamicObject, IDisposable
15+
public class PyObject : DynamicObject, IEnumerable, IDisposable
1616
{
1717
protected internal IntPtr obj = IntPtr.Zero;
1818
private bool disposed = false;

src/runtime/pythonexception.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class PythonException : System.Exception
1313
private IntPtr _pyTB = IntPtr.Zero;
1414
private string _tb = "";
1515
private string _message = "";
16+
private string _pythonTypeName = "";
1617
private bool disposed = false;
1718

1819
public PythonException()
@@ -33,6 +34,8 @@ public PythonException()
3334
type = pyTypeName.ToString();
3435
}
3536

37+
_pythonTypeName = type;
38+
3639
Runtime.XIncref(_pyValue);
3740
using (var pyValue = new PyObject(_pyValue))
3841
{
@@ -132,6 +135,13 @@ public override string StackTrace
132135
get { return _tb; }
133136
}
134137

138+
/// <summary>
139+
/// Python error type name.
140+
/// </summary>
141+
public string PythonTypeName
142+
{
143+
get { return _pythonTypeName; }
144+
}
135145

136146
/// <summary>
137147
/// Dispose Method

0 commit comments

Comments
 (0)