On 8/30/13 6:11 AM, Stefan Behnel wrote:
> Can't you use __cinit__() to set it up?
>
Or use a Python package?
In Cython file foo/_bar.pyx:
=================
cdef class MyCythonClass:
def setup(self): pass
In Python file foo/bar.py:
================
from _bar import MyCythonClass
class MyPythonClass(MyCythonClass):
def __init__(self):
MyCythonClass.__init__(self)
self.setup()
In Python file foo/__init__.py:
==================
from bar import MyPythonClass
__all__ = ['MyPythonClass']
Of course there are numerous other options involving exporting factory
functions, overloading __new__, using metaclasses, or just utilizing
__cinit__.
However: The main thing is "we are all consenting adults". Python
security is not about making stupid decisions totally impossible, as is
common in C++, .NET or Java. In Python we just make dumb mistakes less
likely, and trust that he user is a consenting adult. If the user
nevertheless wants to be a stupid child, and use "MyCythonClass"
directly -- even though it wasn't exported by the package, and even
using it without calling .setup() first -- well that's their bad. Making
dumb ideas completely impossible is not Pythonic anyway.
Sturla