summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-01-13 20:13:12 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2003-01-13 20:13:12 (GMT)
commit1a9975014f7ddc583a2428fe47d0e17261f98b46 (patch)
treefebd9464101af88429c179aac60f378a6ee680dc /Lib/test/test_descr.py
parenta974b3939f8f6239018fd0de44530244812191da (diff)
downloadcpython-1a9975014f7ddc583a2428fe47d0e17261f98b46.zip
cpython-1a9975014f7ddc583a2428fe47d0e17261f98b46.tar.gz
cpython-1a9975014f7ddc583a2428fe47d0e17261f98b46.tar.bz2
Fix SF bug #667147, Segmentation fault printing str subclass
Fix infinite recursion which occurred when printing an object whose __str__() returned self. Will backport
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 023fcc8..da4bd03 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1,6 +1,6 @@
# Test enhancements related to descriptors and new-style classes
-from test.test_support import verify, vereq, verbose, TestFailed, TESTFN
+from test.test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout
from copy import deepcopy
import warnings
@@ -1821,6 +1821,29 @@ def specials():
unsafecmp(1, 1L)
unsafecmp(1L, 1)
+ class Letter(str):
+ def __new__(cls, letter):
+ if letter == 'EPS':
+ return str.__new__(cls)
+ return str.__new__(cls, letter)
+ def __str__(self):
+ if not self:
+ return 'EPS'
+ return self
+
+ # sys.stdout needs to be the original to trigger the recursion bug
+ import sys
+ test_stdout = sys.stdout
+ sys.stdout = get_original_stdout()
+ try:
+ # nothing should actually be printed, this should raise an exception
+ print Letter('w')
+ except RuntimeError:
+ pass
+ else:
+ raise TestFailed, "expected a RuntimeError for print recursion"
+ sys.stdout = test_stdout
+
def weakrefs():
if verbose: print "Testing weak references..."
import weakref