Hi,
Matt D schrieb am 09.07.24 um 16:31:
It's not entirely clear to me what your scenario looks like, but I gather
that you have some kind of hierarchy with overloaded methods where each
instance should be a singleton of the specific class in the hierarchy?
Then my question is: why do you need a (callable) class interface for this
in the first place? Why not just expose the instances as simple module
attributes? Maybe together with their main base class (or an ABC) to
facilitate type checks on user side?
I don't think I have understood the part with the class variable, but a
class variable is really just a global variable in a namespace, so maybe
you can replace the publicly exposed classes with factory functions to keep
the interface callable, and only create the implementation classes
internally? (There's a "@cython.internal" decorator for cases like this.)
Or, as David wrote, stick to Python classes. The implementation of the
methods is then still compiled, but the classes that own them can use all
regular Python class tricks.
Stefan