| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9e5887c commit 1afae4c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,22 +39,23 @@ or the DLL must be loaded in advance. This must be done before calling any other | |||
| 39 | 39 | ||
| 40 | 40 | ### Fixed | |
| 41 | 41 | ||
| 42 | - - Fix incorrect dereference of wrapper object in `tp_repr`, which may result in a program crash | ||
| 43 | - - Fix incorrect dereference in params array handling | ||
| 44 | - - Fixes issue with function resolution when calling overloaded function with keyword arguments from python ([#1097][i1097]) | ||
| 45 | - - Fix `object[]` parameters taking precedence when should not in overload resolution | ||
| 46 | - - Fixed a bug where all .NET class instances were considered Iterable | ||
| 47 | - - Fix incorrect choice of method to invoke when using keyword arguments. | ||
| 48 | - - Fix non-delegate types incorrectly appearing as callable. | ||
| 49 | - - Indexers can now be used with interface objects | ||
| 50 | - - Fixed a bug where indexers could not be used if they were inherited | ||
| 51 | - - Made it possible to use `__len__` also on `ICollection<>` interface objects | ||
| 52 | - - Fixed issue when calling PythonException.Format where another exception would be raise for unnormalized exceptions | ||
| 53 | - - Made it possible to call `ToString`, `GetHashCode`, and `GetType` on inteface objects | ||
| 54 | - - Fixed objects returned by enumerating `PyObject` being disposed too soon | ||
| 55 | - - Incorrectly using a non-generic type with type parameters now produces a helpful Python error instead of throwing NullReferenceException ([#1325][i1325]) | ||
| 56 | - - `import` may now raise errors with more detail than "No module named X" | ||
| 57 | - - Providing an invalid type parameter to a generic type or method produces a helpful Python error | ||
| 42 | + - Fix incorrect dereference of wrapper object in `tp_repr`, which may result in a program crash | ||
| 43 | + - Fix incorrect dereference in params array handling | ||
| 44 | + - Fixes issue with function resolution when calling overloaded function with keyword arguments from python ([#1097][i1097]) | ||
| 45 | + - Fix `object[]` parameters taking precedence when should not in overload resolution | ||
| 46 | + - Fixed a bug where all .NET class instances were considered Iterable | ||
| 47 | + - Fix incorrect choice of method to invoke when using keyword arguments. | ||
| 48 | + - Fix non-delegate types incorrectly appearing as callable. | ||
| 49 | + - Indexers can now be used with interface objects | ||
| 50 | + - Fixed a bug where indexers could not be used if they were inherited | ||
| 51 | + - Made it possible to use `__len__` also on `ICollection<>` interface objects | ||
| 52 | + - Fixed issue when calling PythonException.Format where another exception would be raise for unnormalized exceptions | ||
| 53 | + - Made it possible to call `ToString`, `GetHashCode`, and `GetType` on inteface objects | ||
| 54 | + - Fixed objects returned by enumerating `PyObject` being disposed too soon | ||
| 55 | + - Incorrectly using a non-generic type with type parameters now produces a helpful Python error instead of throwing NullReferenceException | ||
| 56 | + - `import` may now raise errors with more detail than "No module named X" | ||
| 57 | + - Exception stacktraces on `PythonException.StackTrace` are now properly formatted | ||
| 58 | + - Providing an invalid type parameter to a generic type or method produces a helpful Python error | ||
| 58 | 59 | ||
| 59 | 60 | ### Removed | |
| 60 | 61 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,7 +65,21 @@ public void TestPythonExceptionFormat() | |||
| 65 | 65 | } | |
| 66 | 66 | catch (PythonException ex) | |
| 67 | 67 | { | |
| 68 | - Assert.That(ex.Format(), Does.Contain("Traceback").And.Contains("(most recent call last):").And.Contains("ValueError: Error!")); | ||
| 68 | + // Console.WriteLine($"Format: {ex.Format()}"); | ||
| 69 | + // Console.WriteLine($"Stacktrace: {ex.StackTrace}"); | ||
| 70 | + Assert.That( | ||
| 71 | + ex.Format(), | ||
| 72 | + Does.Contain("Traceback") | ||
| 73 | + .And.Contains("(most recent call last):") | ||
| 74 | + .And.Contains("ValueError: Error!") | ||
| 75 | + ); | ||
| 76 | + | ||
| 77 | + // Check that the stacktrace is properly formatted | ||
| 78 | + Assert.That( | ||
| 79 | + ex.StackTrace, | ||
| 80 | + Does.Not.StartWith("[") | ||
| 81 | + .And.Not.Contain("\\n") | ||
| 82 | + ); | ||
| 69 | 83 | } | |
| 70 | 84 | } | |
| 71 | 85 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | using System; | |
| 2 | + using System.Linq; | ||
| 2 | 3 | using System.Runtime.CompilerServices; | |
| 3 | 4 | using System.Text; | |
| 4 | 5 | ||
@@ -13,9 +14,9 @@ public class PythonException : System.Exception, IDisposable | |||
| 13 | 14 | private IntPtr _pyType = IntPtr.Zero; | |
| 14 | 15 | private IntPtr _pyValue = IntPtr.Zero; | |
| 15 | 16 | private IntPtr _pyTB = IntPtr.Zero; | |
| 16 | - private string _tb = ""; | ||
| 17 | - private string _message = ""; | ||
| 18 | - private string _pythonTypeName = ""; | ||
| 17 | + private readonly string _tb = ""; | ||
| 18 | + private readonly string _message = ""; | ||
| 19 | + private readonly string _pythonTypeName = ""; | ||
| 19 | 20 | private bool disposed = false; | |
| 20 | 21 | private bool _finalized = false; | |
| 21 | 22 | ||
@@ -44,16 +45,23 @@ public PythonException() | |||
| 44 | 45 | } | |
| 45 | 46 | _message = type + " : " + message; | |
| 46 | 47 | } | |
| 48 | + | ||
| 47 | 49 | if (_pyTB != IntPtr.Zero) | |
| 48 | 50 | { | |
| 49 | - using (PyObject tb_module = PythonEngine.ImportModule("traceback")) | ||
| 50 | - { | ||
| 51 | - Runtime.XIncref(_pyTB); | ||
| 52 | - using (var pyTB = new PyObject(_pyTB)) | ||
| 53 | - { | ||
| 54 | - _tb = tb_module.InvokeMethod("format_tb", pyTB).ToString(); | ||
| 55 | - } | ||
| 51 | + using PyObject tb_module = PythonEngine.ImportModule("traceback"); | ||
| 52 | + | ||
| 53 | + Runtime.XIncref(_pyTB); | ||
| 54 | + using var pyTB = new PyObject(_pyTB); | ||
| 55 | + | ||
| 56 | + using var tbList = tb_module.InvokeMethod("format_tb", pyTB); | ||
| 57 | + | ||
| 58 | + var sb = new StringBuilder(); | ||
| 59 | + // Reverse Python's traceback list to match the order used in C# | ||
| 60 | + // stacktraces | ||
| 61 | + foreach (var line in tbList.Reverse()) { | ||
| 62 | + sb.Append(line.ToString()); | ||
| 56 | 63 | } | |
| 64 | + _tb = sb.ToString(); | ||
| 57 | 65 | } | |
| 58 | 66 | PythonEngine.ReleaseLock(gs); | |
| 59 | 67 | } | |
@@ -136,10 +144,7 @@ public override string Message | |||
| 136 | 144 | /// <remarks> | |
| 137 | 145 | /// A string representing the python exception stack trace. | |
| 138 | 146 | /// </remarks> | |
| 139 | - public override string StackTrace | ||
| 140 | - { | ||
| 141 | - get { return _tb + base.StackTrace; } | ||
| 142 | - } | ||
| 147 | + public override string StackTrace => $"{_tb}===\n{base.StackTrace}"; | ||
| 143 | 148 | ||
| 144 | 149 | /// <summary> | |
| 145 | 150 | /// Python error type name. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments