Commit a9fa4bda authored by Robert Bradshaw's avatar Robert Bradshaw

Docstrings for special methods

parent eaa47be5
...@@ -6,6 +6,7 @@ import Naming ...@@ -6,6 +6,7 @@ import Naming
import Options import Options
from Cython.Utils import open_new_file from Cython.Utils import open_new_file
from PyrexTypes import py_object_type, typecast from PyrexTypes import py_object_type, typecast
from TypeSlots import get_special_method_signature
class CCodeWriter: class CCodeWriter:
# f file output file # f file output file
...@@ -288,10 +289,15 @@ class CCodeWriter: ...@@ -288,10 +289,15 @@ class CCodeWriter:
doc_code = entry.doc_cname doc_code = entry.doc_cname
else: else:
doc_code = 0 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( self.putln(
'{"%s", (PyCFunction)%s, METH_VARARGS|METH_KEYWORDS, %s}%s' % ( '{"%s", (PyCFunction)%s, %s, %s}%s' % (
entry.name, entry.name,
entry.func_cname, entry.func_cname,
meth_flags,
doc_code, doc_code,
term)) term))
......
...@@ -1079,13 +1079,18 @@ class CClassScope(ClassScope): ...@@ -1079,13 +1079,18 @@ class CClassScope(ClassScope):
def declare_pyfunction(self, name, pos): def declare_pyfunction(self, name, pos):
# Add an entry for a method. # 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) entry = self.declare(name, name, py_object_type, pos)
special_sig = get_special_method_signature(name) special_sig = get_special_method_signature(name)
if special_sig: if special_sig:
# Special methods get put in the method table with a particular
# signature declared in advance.
entry.signature = special_sig entry.signature = special_sig
# Special methods don't get put in the method table
else: else:
entry.signature = pymethod_signature entry.signature = pymethod_signature
self.pyfunc_entries.append(entry) self.pyfunc_entries.append(entry)
return entry return entry
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment