Message402105
I am still fighting with this (and the issues surrounding it) for NumPy. The main point is that my new DTypes in NumPy are metaclasses that extend the (heap)type struct.
That just feels right and matches the structure perfectly, but seems to get awkward when you want (users) to dynamically create new MetaClass instances.
It also works fine: I could allow creating new instances from Python (although I don't need it now) and allow users to create static types (for this I have to fix the size of the additional fields for a stable ABI, but that is fine, I can allocate a new opaque slot).
But cython or heaptypes (stable API) seem not accessible without annoying hacks...
For this concrete issue, would it be acceptable to use the base classes to correctly find the metaclass and use its alloc?
I personally don't see why a new signature would be needed even if the metaclass was to be passed (I do not need this), it seems like you could pass a `Py_tp_meta` slot and not add a new function?
I have attached a potential patch (it is a bit large because it needs to move the `bases` discovery code to before the `res` allocation).
Doing this would allow to provide a `FromSpec` function which internally calls `PyType_FromSpec`.
That may not make things much neater for cython, but it feels like this is really just a bug fix? Unless you want to consider any extension of the type struct an unofficial hack to begin with :).
(Python metaclasses won't get their `__new__` called, but that is already the case, presumably a metaclass author will provide their own `InitFromSpec` function that must be called immediately after type creation, or just create the type completely. I can do the second even now probably, but this tiny change would make it a lot cleaner.)
Trying more desperate angles, I was even wondering today if I should instead petition for Python to "donate" a `tp_metaslot` type slot... A single `void *` unused by `PyType_Type` but available to metatypes to use as they wish.
While a bit strange, that might even simplify some ABI concerns or cython compatibility ;). |
|
Date |
User |
Action |
Args |
2021-09-17 22:54:10 | seberg | set | recipients:
+ seberg, loewis, jcea, amaury.forgeotdarc, belopolsky, pitrou, Arfrever, petr.viktorin, lekma, Alexander.Belopolsky, mattip, Robin.Schreiber, Christian.Tismer, jhaberman, haberman2 |
2021-09-17 22:54:10 | seberg | set | messageid: <1631919250.76.0.374750875076.issue15870@roundup.psfhosted.org> |
2021-09-17 22:54:10 | seberg | link | issue15870 messages |
2021-09-17 22:54:10 | seberg | create | |
|