type.vtabptr_cname,
code.error_goto(entry.pos)))
env.use_utility_code(Nodes.set_vtable_utility_code)
- code.putln(
- 'if (__Pyx_SetAttrString(%s, "%s", (PyObject *)&%s) < 0) %s' % (
- Naming.module_cname,
- scope.class_name,
- typeobj_cname,
- code.error_goto(entry.pos)))
+ if not type.scope.is_internal and not type.scope.directives['internal']:
+ # scope.is_internal is set for types defined by
+ # Cython (such as closures), the 'internal'
+ # directive is set by users
+ code.putln(
+ 'if (__Pyx_SetAttrString(%s, "%s", (PyObject *)&%s) < 0) %s' % (
+ Naming.module_cname,
+ scope.class_name,
+ typeobj_cname,
+ code.error_goto(entry.pos)))
weakref_entry = scope.lookup_here("__weakref__")
if weakref_entry:
if weakref_entry.type is py_object_type:
error(self.pos, "Base class '%s' of type '%s' is incomplete" % (
self.base_class_name, self.class_name))
elif base_class_entry.type.scope and base_class_entry.type.scope.directives and \
- base_class_entry.type.scope.directives.get('final', False):
+ base_class_entry.type.scope.directives['final']:
error(self.pos, "Base class '%s' of type '%s' is final" % (
self.base_class_name, self.class_name))
else:
'wraparound' : True,
'ccomplex' : False, # use C99/C++ for complex types and arith
'callspec' : "",
+ 'final' : False,
+ 'internal' : False,
'profile': False,
'infer_types': None,
'infer_types.verbose': False,
# Override types possibilities above, if needed
directive_types = {
'final' : bool, # final cdef classes and methods
+ 'internal' : bool, # cdef class visibility in the module dict
'infer_types' : bool, # values can be True/None/False
}
directive_scopes = { # defaults to available everywhere
# 'module', 'function', 'class', 'with statement'
'final' : ('cclass',), # add 'method' in the future
+ 'internal' : ('cclass',),
'autotestdict' : ('module',),
'test_assert_path_exists' : ('function',),
'test_fail_if_path_exists' : ('function',),
def slot_code(self, scope):
value = "Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER"
- if not scope.directives.get('final', False):
+ if not scope.directives['final']:
value += "|Py_TPFLAGS_BASETYPE"
if scope.needs_gc():
value += "|Py_TPFLAGS_HAVE_GC"
--- /dev/null
+
+cimport cython
+
+
+@cython.internal
+cdef class InternalType:
+ """
+ NOTE: this doesn't fail because it is never tested !
+ >>> i = InternalType
+ """
+
+cdef class PublicType:
+ """
+ >>> p = PublicType
+ """
+
+def test():
+ """
+ >>> p,i = test()
+
+ >>> p = PublicType
+
+ >>> i = InternalType
+ Traceback (most recent call last):
+ NameError: name 'InternalType' is not defined
+ """
+ p = PublicType
+ i = InternalType
+ return p,i