From 5dc3e3f17ab76b44e0ca29c6ab5b3b95093f5710 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 13 Jun 2006 22:26:13 +0000 Subject: [PATCH] Missed test for rev. 46933; infinite recursion from __coerce__() returning its arguments reversed. --- Lib/test/test_coercion.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_coercion.py b/Lib/test/test_coercion.py index 43568173026..d704e4b7345 100644 --- a/Lib/test/test_coercion.py +++ b/Lib/test/test_coercion.py @@ -2,7 +2,7 @@ import copy import sys import warnings import unittest -from test.test_support import run_unittest +from test.test_support import run_unittest, TestFailed # Fake a number that implements numeric methods through __coerce__ class CoerceNumber: @@ -318,6 +318,24 @@ class CoercionTest(unittest.TestCase): return 0 self.assertEquals(cmp(ClassicWackyComparer(), evil_coercer), 0) + def test_infinite_rec_classic_classes(self): + # if __coerce__() returns its arguments reversed it causes an infinite + # recursion for classic classes. + class Tester: + def __coerce__(self, other): + return other, self + + exc = TestFailed("__coerce__() returning its arguments reverse " + "should raise RuntimeError") + try: + Tester() + 1 + except (RuntimeError, TypeError): + return + except: + raise exc + else: + raise exc + def test_main(): warnings.filterwarnings("ignore", r'complex divmod\(\), // and % are deprecated',