From 554457375dfcbd7ff0e25a5c8729a8d45abeee4e Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Sun, 15 Aug 2010 01:06:51 -0700 Subject: [PATCH] Fix invisible special methods. --- Cython/Compiler/ModuleNode.py | 2 +- Cython/Compiler/Nodes.py | 8 ++++++-- Cython/Compiler/TypeSlots.py | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index cfc04096..204dd8e3 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2045,7 +2045,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): # unless we let PyType_Ready create the slot wrappers we have # a significant performance hit. (See trac #561.) for func in entry.type.scope.pyfunc_entries: - if func.is_special and func.doc: + if func.is_special and func.wrapperbase_cname: code.putln("{"); code.putln( 'PyObject *wrapper = PyObject_GetAttrString((PyObject *)&%s, "%s"); %s' % ( diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 5c0d273b..349c9b86 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -2111,7 +2111,10 @@ class DefNode(FuncDefNode): entry.doc_cname = \ Naming.funcdoc_prefix + prefix + name if entry.is_special: - entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name + if entry.name in TypeSlots.invisible or not entry.doc: + entry.wrapperbase_cname = None + else: + entry.wrapperbase_cname = Naming.wrapperbase_prefix + prefix + name else: entry.doc = None @@ -2226,7 +2229,8 @@ class DefNode(FuncDefNode): if proto_only: return if (Options.docstrings and self.entry.doc and - not self.entry.scope.is_property_scope): + not self.entry.scope.is_property_scope and + (not self.entry.is_special or self.entry.wrapperbase_cname)): docstr = self.entry.doc if docstr.is_unicode: docstr = docstr.utf8encode() diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index 9b35ec88..1745e664 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -8,6 +8,9 @@ import PyrexTypes import StringEncoding import sys +invisible = ['__cinit__', '__dealloc__', '__richcmp__', + '__nonzero__', '__bool__'] + class Signature(object): # Method slot signature descriptor. # -- 2.26.2