| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4f42458 commit cf4d59a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,16 +90,33 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, | |||
| 90 | 90 | var baseTypes = new List<ClassBase>(); | |
| 91 | 91 | ||
| 92 | 92 | var baseClassCount = Runtime.PyTuple_Size(bases); | |
| 93 | + if (baseClassCount == 0) | ||
| 94 | + { | ||
| 95 | + return Exceptions.RaiseTypeError("zero base classes "); | ||
| 96 | + } | ||
| 93 | 97 | ||
| 94 | 98 | for (nint i = 0; i < baseClassCount; i++) | |
| 95 | 99 | { | |
| 96 | 100 | var baseTypeIt = Runtime.PyTuple_GetItem(bases, (int)i); | |
| 97 | 101 | ||
| 98 | 102 | if (GetManagedObject(baseTypeIt) is ClassBase classBaseIt) | |
| 99 | 103 | { | |
| 100 | - if (classBaseIt.type.Valid && classBaseIt.type.Value.IsInterface) | ||
| 104 | + if (!classBaseIt.type.Valid) | ||
| 105 | + { | ||
| 106 | + return Exceptions.RaiseTypeError("Invalid type used as a super type."); | ||
| 107 | + } | ||
| 108 | + if (classBaseIt.type.Value.IsInterface) | ||
| 109 | + { | ||
| 101 | 110 | interfaces.Add(classBaseIt.type.Value); | |
| 102 | - else baseTypes.Add(classBaseIt); | ||
| 111 | + } | ||
| 112 | + else | ||
| 113 | + { | ||
| 114 | + baseTypes.Add(classBaseIt); | ||
| 115 | + } | ||
| 116 | + } | ||
| 117 | + else | ||
| 118 | + { | ||
| 119 | + return Exceptions.RaiseTypeError("Non .NET type used as super class for meta type. This is not supported."); | ||
| 103 | 120 | } | |
| 104 | 121 | } | |
| 105 | 122 | // if the base type count is 0, there might still be interfaces to implement. | |
@@ -111,7 +128,20 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, | |||
| 111 | 128 | // Multiple inheritance is not supported, unless the other types are interfaces | |
| 112 | 129 | if (baseTypes.Count > 1) | |
| 113 | 130 | { | |
| 114 | - return Exceptions.RaiseTypeError("cannot use multiple inheritance with managed classes"); | ||
| 131 | + var types = string.Join(", ", baseTypes.Select(baseType => baseType.type.Value)); | ||
| 132 | + return Exceptions.RaiseTypeError($"Multiple inheritance with managed classes cannot be used. Types: {types} "); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + // check if the list of interfaces contains no duplicates. | ||
| 136 | + if (interfaces.Distinct().Count() != interfaces.Count) | ||
| 137 | + { | ||
| 138 | + // generate a string containing the problematic types. | ||
| 139 | + var duplicateTypes = interfaces.GroupBy(type => type) | ||
| 140 | + .Where(typeGroup => typeGroup.Count() > 1) | ||
| 141 | + .Select(typeGroup => typeGroup.Key); | ||
| 142 | + var duplicateTypesString = string.Join(", ", duplicateTypes); | ||
| 143 | + | ||
| 144 | + return Exceptions.RaiseTypeError($"An interface can only be implemented once. Duplicate types: {duplicateTypesString}"); | ||
| 115 | 145 | } | |
| 116 | 146 | ||
| 117 | 147 | var cb = baseTypes[0]; | |
@@ -133,8 +163,7 @@ public static NewReference tp_new(BorrowedReference tp, BorrowedReference args, | |||
| 133 | 163 | return Exceptions.RaiseTypeError("subclasses of managed classes do not support __slots__"); | |
| 134 | 164 | } | |
| 135 | 165 | ||
| 136 | - // If the base class has a parameterless constructor, or | ||
| 137 | - // if __assembly__ or __namespace__ are in the class dictionary then create | ||
| 166 | + // If __assembly__ or __namespace__ are in the class dictionary then create | ||
| 138 | 167 | // a managed sub type. | |
| 139 | 168 | // This creates a new managed type that can be used from .net to call back | |
| 140 | 169 | // into python. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments