diff options
| author | Neal Norwitz <nnorwitz@gmail.com> | 2003-01-13 20:17:22 +0000 |
|---|---|---|
| committer | Neal Norwitz <nnorwitz@gmail.com> | 2003-01-13 20:17:22 +0000 |
| commit | fbaaab9d25692c4f8bee0f9f680567ba3f46632b (patch) | |
| tree | 684402d1c03c91a650c1ad59b2f4e0e9a5f639a9 /Lib/test | |
| parent | c695e8f6ba391789a8d2e308d47ddc664c071bf6 (diff) | |
| download | cpython-git-fbaaab9d25692c4f8bee0f9f680567ba3f46632b.tar.gz | |
Backport:
Fix SF bug #667147, Segmentation fault printing str subclass
Fix infinite recursion which occurred when printing an object
whose __str__() returned self.
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_descr.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 565d6d9dba..f92bba29c3 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_support import verify, vereq, verbose, TestFailed, TESTFN +from test_support import verify, vereq, verbose, TestFailed, TESTFN, get_original_stdout from copy import deepcopy import warnings @@ -1605,6 +1605,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 |
