From 2895952e1e31fbedd6995d5c532b89c2d3afcaae Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 16 May 2008 19:58:56 +0200 Subject: [PATCH] class names are identifiers, too --- Cython/Compiler/ExprNodes.py | 15 +++++++++------ Cython/Compiler/Nodes.py | 3 +-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index cbcd2586..cb389b07 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2423,11 +2423,10 @@ class ClassNode(ExprNode): # doc ExprNode or None Doc string # module_name string Name of defining module - subexprs = ['name', 'bases', 'doc'] - + subexprs = ['bases', 'doc'] + def analyse_types(self, env): - self.name.analyse_types(env) - self.name = self.name.coerce_to_pyobject(env) + self.cname = env.intern_identifier(self.name) self.bases.analyse_types(env) if self.doc: self.doc.analyse_types(env) @@ -2436,7 +2435,7 @@ class ClassNode(ExprNode): self.type = py_object_type self.is_temp = 1 env.use_utility_code(create_class_utility_code); - + def generate_result_code(self, code): if self.doc: code.put_error_if_neg(self.pos, @@ -2448,7 +2447,7 @@ class ClassNode(ExprNode): self.result_code, self.bases.py_result(), self.dict.py_result(), - self.name.py_result(), + self.cname, self.module_name, code.error_goto_if_null(self.result_code, self.pos))) @@ -4022,7 +4021,11 @@ static PyObject *__Pyx_CreateClass( PyObject *py_modname; PyObject *result = 0; + #if PY_MAJOR_VERSION < 3 py_modname = PyString_FromString(modname); + #else + py_modname = PyUnicode_FromString(modname); + #endif if (!py_modname) goto bad; if (PyDict_SetItemString(dict, "__module__", py_modname) < 0) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index a352a685..41e6a542 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -1967,8 +1967,7 @@ class PyClassDefNode(StatNode, BlockNode): doc_node = ExprNodes.StringNode(pos, value = doc) else: doc_node = None - self.classobj = ExprNodes.ClassNode(pos, - name = ExprNodes.StringNode(pos, value = name), + self.classobj = ExprNodes.ClassNode(pos, name = name, bases = bases, dict = self.dict, doc = doc_node) self.target = ExprNodes.NameNode(pos, name = name) -- 2.26.2