| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,18 +57,16 @@ public class PyScope : DynamicObject, IDisposable | |||
| 57 | 57 | /// </remarks> | |
| 58 | 58 | internal PyScope(IntPtr ptr, PyScopeManager manager) | |
| 59 | 59 | { | |
| 60 | - if (Runtime.PyObject_Type(ptr) != Runtime.PyModuleType) | ||
| 60 | + if (!Runtime.PyType_IsSubtype(Runtime.PyObject_TYPE(ptr), Runtime.PyModuleType)) | ||
| 61 | 61 | { | |
| 62 | 62 | throw new PyScopeException("object is not a module"); | |
| 63 | 63 | } | |
| 64 | 64 | Manager = manager ?? PyScopeManager.Global; | |
| 65 | 65 | obj = ptr; | |
| 66 | 66 | //Refcount of the variables not increase | |
| 67 | 67 | variables = Runtime.PyModule_GetDict(obj); | |
| 68 | - if (variables == IntPtr.Zero) | ||
| 69 | - { | ||
| 70 | - throw new PythonException(); | ||
| 71 | - } | ||
| 68 | + Runtime.CheckExceptionOccurred(); | ||
| 69 | + | ||
| 72 | 70 | Runtime.PyDict_SetItemString( | |
| 73 | 71 | variables, "__builtins__", | |
| 74 | 72 | Runtime.PyEval_GetBuiltins() | |
@@ -123,7 +121,7 @@ public dynamic Import(string name, string asname = null) | |||
| 123 | 121 | PyObject module = PythonEngine.ImportModule(name); | |
| 124 | 122 | Import(module, asname); | |
| 125 | 123 | return module; | |
| 126 | - } | ||
| 124 | + } | ||
| 127 | 125 | } | |
| 128 | 126 | ||
| 129 | 127 | /// <summary> | |
@@ -290,7 +288,7 @@ public PyObject Eval(string code, PyDict locals = null) | |||
| 290 | 288 | /// Evaluate a Python expression | |
| 291 | 289 | /// </summary> | |
| 292 | 290 | /// <remarks> | |
| 293 | - /// Evaluate a Python expression | ||
| 291 | + /// Evaluate a Python expression | ||
| 294 | 292 | /// and convert the result to a Managed Object of given type. | |
| 295 | 293 | /// </remarks> | |
| 296 | 294 | public T Eval<T>(string code, PyDict locals = null) | |
@@ -400,7 +398,7 @@ public PyObject Get(string name) | |||
| 400 | 398 | { | |
| 401 | 399 | PyObject scope; | |
| 402 | 400 | var state = TryGet(name, out scope); | |
| 403 | - if(!state) | ||
| 401 | + if (!state) | ||
| 404 | 402 | { | |
| 405 | 403 | throw new PyScopeException($"The scope of name '{Name}' has no attribute '{name}'"); | |
| 406 | 404 | } | |
@@ -447,7 +445,7 @@ public bool TryGet(string name, out PyObject value) | |||
| 447 | 445 | /// Get Method | |
| 448 | 446 | /// </summary> | |
| 449 | 447 | /// <remarks> | |
| 450 | - /// Obtain the value of the variable of given name, | ||
| 448 | + /// Obtain the value of the variable of given name, | ||
| 451 | 449 | /// and convert the result to a Managed Object of given type. | |
| 452 | 450 | /// If the variable does not exist, throw an Exception. | |
| 453 | 451 | /// </remarks> | |
@@ -466,7 +464,7 @@ public T Get<T>(string name) | |||
| 466 | 464 | /// TryGet Method | |
| 467 | 465 | /// </summary> | |
| 468 | 466 | /// <remarks> | |
| 469 | - /// Obtain the value of the variable of given name, | ||
| 467 | + /// Obtain the value of the variable of given name, | ||
| 470 | 468 | /// and convert the result to a Managed Object of given type. | |
| 471 | 469 | /// If the variable does not exist, return false. | |
| 472 | 470 | /// </remarks> | |
@@ -479,18 +477,18 @@ public bool TryGet<T>(string name, out T value) | |||
| 479 | 477 | { | |
| 480 | 478 | value = default(T); | |
| 481 | 479 | return false; | |
| 482 | - } | ||
| 480 | + } | ||
| 483 | 481 | if (pyObj == null) | |
| 484 | 482 | { | |
| 485 | - if(typeof(T).IsValueType) | ||
| 483 | + if (typeof(T).IsValueType) | ||
| 486 | 484 | { | |
| 487 | 485 | throw new PyScopeException($"The value of the attribute '{name}' is None which cannot be convert to '{typeof(T).ToString()}'"); | |
| 488 | 486 | } | |
| 489 | 487 | else | |
| 490 | 488 | { | |
| 491 | 489 | value = default(T); | |
| 492 | 490 | return true; | |
| 493 | - } | ||
| 491 | + } | ||
| 494 | 492 | } | |
| 495 | 493 | value = pyObj.As<T>(); | |
| 496 | 494 | return true; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments