| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f82aeea commit 9ebfbde
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][]. | |||
| 22 | 22 | ### Fixed | |
| 23 | 23 | ||
| 24 | 24 | - Fixed RecursionError for reverse operators on C# operable types from python. See #2240 | |
| 25 | + - Fixed crash when .NET event has no `AddMethod` | ||
| 25 | 26 | - Fixed probing for assemblies in `sys.path` failing when a path in `sys.path` has invalid characters. See #2376 | |
| 26 | 27 | ||
| 27 | 28 | ## [3.0.3](https://github.com/pythonnet/pythonnet/releases/tag/v3.0.3) - 2023-10-11 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -290,11 +290,13 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p | |||
| 290 | 290 | ||
| 291 | 291 | internal static bool ShouldBindMethod(MethodBase mb) | |
| 292 | 292 | { | |
| 293 | + if (mb is null) throw new ArgumentNullException(nameof(mb)); | ||
| 293 | 294 | return (mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly); | |
| 294 | 295 | } | |
| 295 | 296 | ||
| 296 | 297 | internal static bool ShouldBindField(FieldInfo fi) | |
| 297 | 298 | { | |
| 299 | + if (fi is null) throw new ArgumentNullException(nameof(fi)); | ||
| 298 | 300 | return (fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly); | |
| 299 | 301 | } | |
| 300 | 302 | ||
@@ -326,7 +328,7 @@ internal static bool ShouldBindProperty(PropertyInfo pi) | |||
| 326 | 328 | ||
| 327 | 329 | internal static bool ShouldBindEvent(EventInfo ei) | |
| 328 | 330 | { | |
| 329 | - return ShouldBindMethod(ei.GetAddMethod(true)); | ||
| 331 | + return ei.GetAddMethod(true) is { } add && ShouldBindMethod(add); | ||
| 330 | 332 | } | |
| 331 | 333 | ||
| 332 | 334 | private static ClassInfo GetClassInfo(Type type, ClassBase impl) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,9 @@ | |||
| 1 | + using System; | ||
| 2 | + | ||
| 3 | + namespace Python.Runtime; | ||
| 4 | + | ||
| 5 | + public class InternalPythonnetException : Exception | ||
| 6 | + { | ||
| 7 | + public InternalPythonnetException(string message, Exception innerException) | ||
| 8 | + : base(message, innerException) { } | ||
| 9 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,22 +30,29 @@ public static ReflectedClrType GetOrCreate(Type type) | |||
| 30 | 30 | return pyType; | |
| 31 | 31 | } | |
| 32 | 32 | ||
| 33 | - // Ensure, that matching Python type exists first. | ||
| 34 | - // It is required for self-referential classes | ||
| 35 | - // (e.g. with members, that refer to the same class) | ||
| 36 | - pyType = AllocateClass(type); | ||
| 37 | - ClassManager.cache.Add(type, pyType); | ||
| 33 | + try | ||
| 34 | + { | ||
| 35 | + // Ensure, that matching Python type exists first. | ||
| 36 | + // It is required for self-referential classes | ||
| 37 | + // (e.g. with members, that refer to the same class) | ||
| 38 | + pyType = AllocateClass(type); | ||
| 39 | + ClassManager.cache.Add(type, pyType); | ||
| 38 | 40 | ||
| 39 | - var impl = ClassManager.CreateClass(type); | ||
| 41 | + var impl = ClassManager.CreateClass(type); | ||
| 40 | 42 | ||
| 41 | - TypeManager.InitializeClassCore(type, pyType, impl); | ||
| 43 | + TypeManager.InitializeClassCore(type, pyType, impl); | ||
| 42 | 44 | ||
| 43 | - ClassManager.InitClassBase(type, impl, pyType); | ||
| 45 | + ClassManager.InitClassBase(type, impl, pyType); | ||
| 44 | 46 | ||
| 45 | - // Now we force initialize the Python type object to reflect the given | ||
| 46 | - // managed type, filling the Python type slots with thunks that | ||
| 47 | - // point to the managed methods providing the implementation. | ||
| 48 | - TypeManager.InitializeClass(pyType, impl, type); | ||
| 47 | + // Now we force initialize the Python type object to reflect the given | ||
| 48 | + // managed type, filling the Python type slots with thunks that | ||
| 49 | + // point to the managed methods providing the implementation. | ||
| 50 | + TypeManager.InitializeClass(pyType, impl, type); | ||
| 51 | + } | ||
| 52 | + catch (Exception e) | ||
| 53 | + { | ||
| 54 | + throw new InternalPythonnetException($"Failed to create Python type for {type.FullName}", e); | ||
| 55 | + } | ||
| 49 | 56 | ||
| 50 | 57 | return pyType; | |
| 51 | 58 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments