Commit 24f0ceee authored by Lisandro Dalcin's avatar Lisandro Dalcin

do not emit C code for unused special method docstrings

parent 12ad333d
......@@ -11,7 +11,8 @@ import Symtab
class AutoTestDictTransform(ScopeTrackingTransform):
# Handles autotestdict directive
blacklist = ['__cinit__', '__dealloc__', '__richcmp__', '__nonzero__']
blacklist = ['__cinit__', '__dealloc__', '__richcmp__', '__nonzero__',
'__len__', '__contains__']
def visit_ModuleNode(self, node):
if node.is_pxd:
......
......@@ -1535,7 +1535,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_method_table(self, env, code):
code.putln("")
code.putln(
"static struct PyMethodDef %s[] = {" %
"static PyMethodDef %s[] = {" %
env.method_table_cname)
for entry in env.pyfunc_entries:
code.put_pymethoddef(entry, ",")
......
......@@ -2086,7 +2086,11 @@ class DefNode(FuncDefNode):
code.putln("%s; /*proto*/" % header)
if proto_only:
return
if self.entry.doc and Options.docstrings:
if (Options.docstrings and self.entry.doc and
(not self.entry.is_special or
self.entry.signature.method_flags()) and
not self.entry.scope.is_property_scope
):
docstr = self.entry.doc
if docstr.is_unicode:
docstr = docstr.utf8encode()
......
......@@ -207,6 +207,8 @@ class Scope(object):
# return_type PyrexType or None Return type of function owning scope
# is_py_class_scope boolean Is a Python class scope
# is_c_class_scope boolean Is an extension type scope
# is_cpp_class_scope boolean Is a C++ class scope
# is_property_scope boolean Is a extension type property scope
# scope_prefix string Disambiguator for C names
# in_cinclude boolean Suppress C declaration code
# qualified_name string "modname" or "modname.classname"
......@@ -220,6 +222,7 @@ class Scope(object):
is_py_class_scope = 0
is_c_class_scope = 0
is_cpp_class_scope = 0
is_property_scope = 0
is_module_scope = 0
scope_prefix = ""
in_cinclude = 0
......@@ -1619,6 +1622,8 @@ class PropertyScope(Scope):
# a property of an extension type.
#
# parent_type PyExtensionType The type to which the property belongs
is_property_scope = 1
def declare_pyfunction(self, name, pos):
# Add an entry for a method.
......
cdef class C:
def __cinit__(self):
"This is an unusable docstring."
def __init__(self):
"This is an unusable docstring."
def __dealloc__(self):
"This is an unusable docstring."
def __richcmp__(self, other, int op):
"This is an unusable docstring."
def __nonzero__(self):
"This is an unusable docstring."
return False
def __contains__(self, other):
"This is an unusable docstring."
property foo:
def __get__(self):
"So is this."
def __set__(self, x):
"And here is another one."
def __add__(self, other):
"usable docstring"
def __iter__(self):
"usable docstring"
return False
def __next__(self):
"usable docstring"
return False
......@@ -110,4 +110,20 @@ cdef class MyCdefClass:
False
"""
def __len__(self):
"""
Should not be included, as it can't be looked up with getattr in Py 3.1
>>> True
False
"""
def __contains__(self, value):
"""
Should not be included, as it can't be looked up with getattr in Py 3.1
>>> True
False
"""
cdeffunc()
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