From 8b6131afbabbfef27980bd2fd7e3fee4f1fd8a5b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 24 Nov 2017 09:00:29 +0100 Subject: Repair "__richcmp__" generation for special comparison methods with docstrings. Closes #2019. --- Cython/Compiler/ModuleNode.py | 4 ++-- tests/run/ext_auto_richcmp.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index d6c322e2b..fb652171e 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2962,8 +2962,8 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): is_buffer = func.name in ('__getbuffer__', '__releasebuffer__') if (func.is_special and Options.docstrings and func.wrapperbase_cname and not is_buffer): - slot = TypeSlots.method_name_to_slot[func.name] - preprocessor_guard = slot.preprocessor_guard_code() + slot = TypeSlots.method_name_to_slot.get(func.name) + preprocessor_guard = slot.preprocessor_guard_code() if slot else None if preprocessor_guard: code.putln(preprocessor_guard) code.putln('#if CYTHON_COMPILING_IN_CPYTHON') diff --git a/tests/run/ext_auto_richcmp.py b/tests/run/ext_auto_richcmp.py index 3d8f87659..3d940fd60 100644 --- a/tests/run/ext_auto_richcmp.py +++ b/tests/run/ext_auto_richcmp.py @@ -78,8 +78,12 @@ class ClassEq(X): ... else: a >= b Traceback (most recent call last): TypeError... + + >>> print(a.__eq__.__doc__) + EQ """ def __eq__(self, other): + """EQ""" assert 1 <= self.x <= 2 assert isinstance(self, ClassEq), type(self) if isinstance(other, X): @@ -141,8 +145,14 @@ class ClassEqNe(ClassEq): ... else: a >= b Traceback (most recent call last): TypeError... + + #>>> print(a.__eq__.__doc__) + #EQ + >>> print(a.__ne__.__doc__) + NE """ def __ne__(self, other): + """NE""" assert 1 <= self.x <= 2 assert isinstance(self, ClassEqNe), type(self) if isinstance(other, X): @@ -240,8 +250,16 @@ class ClassEqNeGe(ClassEqNe): ... else: a >= 'x' Traceback (most recent call last): TypeError... + + #>>> print(a.__eq__.__doc__) + #EQ + #>>> print(a.__ne__.__doc__) + #NE + >>> print(a.__ge__.__doc__) + GE """ def __ge__(self, other): + """GE""" assert 1 <= self.x <= 2 assert isinstance(self, ClassEqNeGe), type(self) if isinstance(other, X): -- cgit v1.2.1