From: Robert Bradshaw Date: Fri, 17 Aug 2007 22:46:16 +0000 (-0700) Subject: Docstrings for special methods X-Git-Tag: 0.9.6.14~29^2~129^2~17^2~6 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a9fa4bda1d1dfd86470b1daf1eff2f66f855c7d9;p=cython.git Docstrings for special methods --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 196c4172..87b877a2 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -6,6 +6,7 @@ import Naming import Options from Cython.Utils import open_new_file from PyrexTypes import py_object_type, typecast +from TypeSlots import get_special_method_signature class CCodeWriter: # f file output file @@ -288,10 +289,15 @@ class CCodeWriter: doc_code = entry.doc_cname else: doc_code = 0 + # Add METH_COEXIST to special methods + meth_flags = "METH_VARARGS|METH_KEYWORDS" + if get_special_method_signature(entry.name): + meth_flags = "METH_VARARGS|METH_KEYWORDS|METH_COEXIST" self.putln( - '{"%s", (PyCFunction)%s, METH_VARARGS|METH_KEYWORDS, %s}%s' % ( + '{"%s", (PyCFunction)%s, %s, %s}%s' % ( entry.name, - entry.func_cname, + entry.func_cname, + meth_flags, doc_code, term)) diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 9c437f19..4aa3a7da 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -1079,14 +1079,19 @@ class CClassScope(ClassScope): def declare_pyfunction(self, name, pos): # Add an entry for a method. + if name in ('__eq__', '__ne__', '__lt__', '__gt__', '__le__', '__ge__'): + error(pos, "Special method %s must be implemented via __richcmp__" +% name) entry = self.declare(name, name, py_object_type, pos) special_sig = get_special_method_signature(name) if special_sig: + # Special methods get put in the method table with a particular + # signature declared in advance. entry.signature = special_sig - # Special methods don't get put in the method table else: entry.signature = pymethod_signature - self.pyfunc_entries.append(entry) + + self.pyfunc_entries.append(entry) return entry def declare_cfunction(self, name, type, pos,