summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_descr.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-06-11 21:38:39 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-06-11 21:38:39 (GMT)
commit5de48bdd195b14426c772b4c61290aef7f33e3ec (patch)
treee4411088f62f76b183b18d543b4c4b64d4076d65 /Lib/test/test_descr.py
parent80bfb725af0809308264d526ac6a024fc8386643 (diff)
downloadcpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.zip
cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.tar.gz
cpython-5de48bdd195b14426c772b4c61290aef7f33e3ec.tar.bz2
Simplify various spots where: str() is called on something
that already is a string or the existence of the str class is checked or a check is done for str twice. These all stem from the initial unicode->str replacement.
Diffstat (limited to 'Lib/test/test_descr.py')
-rw-r--r--Lib/test/test_descr.py57
1 files changed, 23 insertions, 34 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index fca0061..bcbd096 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -265,7 +265,7 @@ def test_dir():
del junk
# Just make sure these don't blow up!
- for arg in 2, 2, 2j, 2e0, [2], "2", "2", (2,), {2:2}, type, test_dir:
+ for arg in 2, 2, 2j, 2e0, [2], "2", b"2", (2,), {2:2}, type, test_dir:
dir(arg)
# Test dir on custom classes. Since these have object as a
@@ -1117,34 +1117,29 @@ def slots():
vereq(c.abc, 5)
# Test unicode slot names
+ # Test a single unicode string is not expanded as a sequence.
+ class C(object):
+ __slots__ = "abc"
+ c = C()
+ c.abc = 5
+ vereq(c.abc, 5)
+
+ # _unicode_to_string used to modify slots in certain circumstances
+ slots = ("foo", "bar")
+ class C(object):
+ __slots__ = slots
+ x = C()
+ x.foo = 5
+ vereq(x.foo, 5)
+ veris(type(slots[0]), str)
+ # this used to leak references
try:
- str
- except NameError:
+ class C(object):
+ __slots__ = [chr(128)]
+ except (TypeError, UnicodeEncodeError):
pass
else:
- # Test a single unicode string is not expanded as a sequence.
- class C(object):
- __slots__ = str("abc")
- c = C()
- c.abc = 5
- vereq(c.abc, 5)
-
- # _unicode_to_string used to modify slots in certain circumstances
- slots = (str("foo"), str("bar"))
- class C(object):
- __slots__ = slots
- x = C()
- x.foo = 5
- vereq(x.foo, 5)
- veris(type(slots[0]), str)
- # this used to leak references
- try:
- class C(object):
- __slots__ = [chr(128)]
- except (TypeError, UnicodeEncodeError):
- pass
- else:
- raise TestFailed, "[unichr(128)] slots not caught"
+ raise TestFailed, "[unichr(128)] slots not caught"
# Test leaks
class Counted(object):
@@ -2693,14 +2688,8 @@ def setclass():
__slots__ = ["a", "b"]
class H(object):
__slots__ = ["b", "a"]
- try:
- str
- except NameError:
- class I(object):
- __slots__ = ["a", "b"]
- else:
- class I(object):
- __slots__ = [str("a"), str("b")]
+ class I(object):
+ __slots__ = ["a", "b"]
class J(object):
__slots__ = ["c", "b"]
class K(object):