Permalink
Browse files

do not emit C code for unused special method docstrings

  • Loading branch information...
1 parent 12ad333 commit 24f0ceeed648977206c413104faaf9807e0b92b7 @dalcinl dalcinl committed Apr 15, 2010
@@ -11,7 +11,8 @@
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 @@ def generate_typeobj_definition(self, modname, entry, code):
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, ",")
View
@@ -2086,7 +2086,11 @@ def generate_function_header(self, code, with_pymethdef, proto_only=0):
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.
@@ -1,8 +1,30 @@
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
+
View
@@ -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()

0 comments on commit 24f0cee

Please sign in to comment.