diff --git a/src/CSnakes.Runtime/PythonRuntimeException.cs b/src/CSnakes.Runtime/PythonRuntimeException.cs index 4ae89b7b..b593602d 100644 --- a/src/CSnakes.Runtime/PythonRuntimeException.cs +++ b/src/CSnakes.Runtime/PythonRuntimeException.cs @@ -19,18 +19,13 @@ public PythonRuntimeException(PyObject? exception, PyObject? traceback): base(ex Data["globals"] = traceback.GetAttr("tb_frame").GetAttr("f_globals").As>(); } - private static PythonRuntimeException? GetPythonInnerException(PyObject? exception) - { - if (exception is null) - { - return null; - } - if (exception.HasAttr("__cause__") && !exception.GetAttr("__cause__").IsNone()) - { - return new PythonRuntimeException(exception.GetAttr("__cause__"), null); - } - return null; - } + private static PythonRuntimeException? GetPythonInnerException(PyObject? exception) => + exception is { } someException + && someException.HasAttr("__cause__") + && someException.GetAttr("__cause__") is var cause + && !cause.IsNone() + ? new PythonRuntimeException(cause, null) + : null; public string[] PythonStackTrace {