Start to implement PyType_FromSpec type approach by koubaa · Pull Request #1196 · pythonnet/pythonnet
@koubaa have you tried this code (Sub class) on master without your change? Does it work? If it does not, can you contribute a test (mark it disabled/inconclusive)? Then I can try to work on it outside of this PR.
The overload of CreateType you modified only works for metatypes defined in Python.Runtime (e.g. children of ManagedType). All other CLR types are handled via
| internal static IntPtr CreateType(ManagedType impl, Type clrType) |
System.Exception, System.Object and all derived types.
It is probably related to my shenanigans with a similar problem. You might want to ask a similar question on StackOverflow about the relationship between PyType_FromSpec and tp_basicsize. The documentation is surprisingly scarce.
I just checked on Win64 Python's reflection of System.Exception takes 80 bytes == ExceptionOffset.Size(), which is as expected. However, the Sub class takes 88 bytes, which is not. We need an explanation as to why Python adds extra bytes when deriving from System.Exception. Depending on it we should either change the Assert condition, or change our code to ensure Python does not need to add anything when deriving from System.Exception.
I just checked and the reflected System.Exception type has tp_dictoffset > 0, so that's not it.