[Python-3000] [Python-checkins] r55079 - in python/branches/py3k-struni/Lib: [many files] (original) (raw)

Walter Dörwald walter at livinglogic.de
Thu May 3 12:01:48 CEST 2007


guido.van.rossum wrote:

Author: guido.van.rossum Date: Wed May 2 21:09:54 2007 New Revision: 55079

Modified: Log: [...] Rip out all the u"..." literals and calls to unicode().

That might be one of the largest diffs in Python's history. ;)

Some of the changes lead to strange code like isinstance(foo, (str, str))

Below are the strange spots I noticed at first glance. I'm sure I missed a few.

Servus, Walter

[...] Modified: python/branches/py3k-struni/Lib/copy.py ============================================================================== --- python/branches/py3k-struni/Lib/copy.py (original) +++ python/branches/py3k-struni/Lib/copy.py Wed May 2 21:09:54 2007 @@ -186,7 +186,7 @@ pass d[str] = deepcopyatomic try: - d[unicode] = deepcopyatomic + d[str] = deepcopyatomic except NameError: pass

The try:except: is unnecessary now.

try:

Modified: python/branches/py3k-struni/Lib/ctypes/init.py ============================================================================== --- python/branches/py3k-struni/Lib/ctypes/init.py (original) +++ python/branches/py3k-struni/Lib/ctypes/init.py Wed May 2 21:09:54 2007 @@ -59,7 +59,7 @@ createstringbuffer(anInteger) -> character array createstringbuffer(aString, anInteger) -> character array """ - if isinstance(init, (str, unicode)): + if isinstance(init, (str, str)): if size is None: size = len(init)+1 buftype = cchar * size @@ -281,7 +281,7 @@ createunicodebuffer(anInteger) -> character array createunicodebuffer(aString, anInteger) -> character array """ - if isinstance(init, (str, unicode)): + if isinstance(init, (str, str)): if size is None: size = len(init)+1 buftype = cwchar * size

This could be simplyfied to: if isinstance(init, str):

Modified: python/branches/py3k-struni/Lib/distutils/command/bdistwininst.py ============================================================================== --- python/branches/py3k-struni/Lib/distutils/command/bdistwininst.py (original) +++ python/branches/py3k-struni/Lib/distutils/command/bdistwininst.py Wed May 2 21:09:54 2007 @@ -247,11 +247,11 @@

# Convert cfgdata from unicode to ascii, mbcs encoded try: - unicode + str except NameError: pass else: - if isinstance(cfgdata, unicode): + if isinstance(cfgdata, str): cfgdata = cfgdata.encode("mbcs")

The try:except: is again unnecessary.

Modified: python/branches/py3k-struni/Lib/doctest.py ============================================================================== --- python/branches/py3k-struni/Lib/doctest.py (original) +++ python/branches/py3k-struni/Lib/doctest.py Wed May 2 21:09:54 2007 @@ -196,7 +196,7 @@ """ if inspect.ismodule(module): return module - elif isinstance(module, (str, unicode)): + elif isinstance(module, (str, str)):

-> elif isinstance(module, str):

Modified: python/branches/py3k-struni/Lib/encodings/idna.py ============================================================================== --- python/branches/py3k-struni/Lib/encodings/idna.py (original) +++ python/branches/py3k-struni/Lib/encodings/idna.py Wed May 2 21:09:54 2007 @@ -4,11 +4,11 @@ from unicodedata import ucd320 as unicodedata

# IDNA section 3.1 -dots = re.compile(u"[\u002E\u3002\uFF0E\uFF61]") +dots = re.compile("[\u002E\u3002\uFF0E\uFF61]") # IDNA section 5 aceprefix = "xn--" -uaceprefix = unicode(aceprefix, "ascii") +uaceprefix = str(aceprefix, "ascii")

This looks unnecessary to me.

Modified: python/branches/py3k-struni/Lib/idlelib/PyParse.py ============================================================================== --- python/branches/py3k-struni/Lib/idlelib/PyParse.py (original) +++ python/branches/py3k-struni/Lib/idlelib/PyParse.py Wed May 2 21:09:54 2007 @@ -105,7 +105,7 @@ del ch

try: - UnicodeType = type(unicode("")) + UnicodeType = type(str("")) except NameError: UnicodeType = None

This should probably be: UnicodeType = str (or the code could directly use str)

Modified: python/branches/py3k-struni/Lib/lib-tk/Tkinter.py ============================================================================== --- python/branches/py3k-struni/Lib/lib-tk/Tkinter.py (original) +++ python/branches/py3k-struni/Lib/lib-tk/Tkinter.py Wed May 2 21:09:54 2007 @@ -3736,7 +3736,7 @@ text = "This is Tcl/Tk version %s" % TclVersion if TclVersion >= 8.1: try: - text = text + unicode("\nThis should be a cedilla: \347", + text = text + str("\nThis should be a cedilla: \347", "iso-8859-1")

Better: text = text + "\nThis should be a cedilla: \xe7"

Modified: python/branches/py3k-struni/Lib/pickle.py ============================================================================== --- python/branches/py3k-struni/Lib/pickle.py (original) +++ python/branches/py3k-struni/Lib/pickle.py Wed May 2 21:09:54 2007 @@ -523,22 +523,22 @@ if StringType == UnicodeType: # This is true for Jython

What's happening here?

[...]

Modified: python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py ============================================================================== --- python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py (original) +++ python/branches/py3k-struni/Lib/plat-mac/EasyDialogs.py Wed May 2 21:09:54 2007 @@ -662,7 +662,7 @@ return tpwanted(rr.selection[0]) if issubclass(tpwanted, str): return tpwanted(rr.selectionfsr[0].aspathname()) - if issubclass(tpwanted, unicode): + if issubclass(tpwanted, str): return tpwanted(rr.selectionfsr[0].aspathname(), 'utf8') raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)

@@ -713,7 +713,7 @@ raise TypeError, "Cannot pass wanted=FSRef to AskFileForSave" if issubclass(tpwanted, Carbon.File.FSSpec): return tpwanted(rr.selection[0]) - if issubclass(tpwanted, (str, unicode)): + if issubclass(tpwanted, (str, str)):

-> if issubclass(tpwanted, str):

if sys.platform == 'mac': fullpath = rr.selection[0].aspathname() else: @@ -722,10 +722,10 @@ pardirfss = Carbon.File.FSSpec((vrefnum, dirid, '')) pardirfsr = Carbon.File.FSRef(pardirfss) pardirpath = pardirfsr.FSRefMakePath() # This is utf-8 - nameutf8 = unicode(name, 'macroman').encode('utf8') + nameutf8 = str(name, 'macroman').encode('utf8') fullpath = os.path.join(pardirpath, nameutf8) - if issubclass(tpwanted, unicode): - return unicode(fullpath, 'utf8') + if issubclass(tpwanted, str): + return str(fullpath, 'utf8') return tpwanted(fullpath) raise TypeError, "Unknown value for argument 'wanted': %s" % repr(tpwanted)

@@ -775,7 +775,7 @@ return tpwanted(rr.selection[0]) if issubclass(tpwanted, str): return tpwanted(rr.selectionfsr[0].aspathname()) - if issubclass(tpwanted, unicode): + if issubclass(tpwanted, str):

This does the same check twice.

Modified: python/branches/py3k-struni/Lib/plat-mac/plistlib.py ============================================================================== --- python/branches/py3k-struni/Lib/plat-mac/plistlib.py (original) +++ python/branches/py3k-struni/Lib/plat-mac/plistlib.py Wed May 2 21:09:54 2007 @@ -70,7 +70,7 @@ usually is a dictionary). """ didOpen = 0 - if isinstance(pathOrFile, (str, unicode)): + if isinstance(pathOrFile, (str, str)):

-> if isinstance(pathOrFile, str):

pathOrFile = open(pathOrFile) didOpen = 1 p = PlistParser() @@ -85,7 +85,7 @@ file name or a (writable) file object. """ didOpen = 0 - if isinstance(pathOrFile, (str, unicode)): + if isinstance(pathOrFile, (str, str)):

-> if isinstance(pathOrFile, str):

pathOrFile = open(pathOrFile, "w") didOpen = 1 writer = PlistWriter(pathOrFile) @@ -231,7 +231,7 @@ DumbXMLWriter.init(self, file, indentLevel, indent)

def writeValue(self, value): - if isinstance(value, (str, unicode)): + if isinstance(value, (str, str)):

-> if isinstance(value, str):

self.simpleElement("string", value) elif isinstance(value, bool): # must switch for bool before int, as bool is a @@ -270,7 +270,7 @@ self.beginElement("dict") items = sorted(d.items()) for key, value in items: - if not isinstance(key, (str, unicode)): + if not isinstance(key, (str, str)):

-> if not isinstance(key, str):

Modified: python/branches/py3k-struni/Lib/sqlite3/test/factory.py ============================================================================== --- python/branches/py3k-struni/Lib/sqlite3/test/factory.py (original) +++ python/branches/py3k-struni/Lib/sqlite3/test/factory.py Wed May 2 21:09:54 2007 @@ -139,31 +139,31 @@ self.con = sqlite.connect(":memory:")

def CheckUnicode(self): - austria = unicode("�sterreich", "latin1") + austria = str("�sterreich", "latin1") row = self.con.execute("select ?", (austria,)).fetchone() - self.failUnless(type(row[0]) == unicode, "type of row[0] must be unicode") + self.failUnless(type(row[0]) == str, "type of row[0] must be unicode") def CheckString(self): self.con.textfactory = str - austria = unicode("�sterreich", "latin1") + austria = str("�sterreich", "latin1") row = self.con.execute("select ?", (austria,)).fetchone() self.failUnless(type(row[0]) == str, "type of row[0] must be str") self.failUnless(row[0] == austria.encode("utf-8"), "column must equal original data in UTF-8")

It looks like both those test do the same thing now.

Modified: python/branches/py3k-struni/Lib/tarfile.py ============================================================================== --- python/branches/py3k-struni/Lib/tarfile.py (original) +++ python/branches/py3k-struni/Lib/tarfile.py Wed May 2 21:09:54 2007 @@ -1031,7 +1031,7 @@ for name, digits in (("uid", 8), ("gid", 8), ("size", 12), ("mtime", 12)): val = info[name] if not 0 <= val < 8 ** (digits - 1) or isinstance(val, float): - paxheaders[name] = unicode(val) + paxheaders[name] = str(val) info[name] = 0

if paxheaders: @@ -1054,12 +1054,12 @@ @staticmethod def tounicode(value, encoding): - if isinstance(value, unicode): + if isinstance(value, str): return value elif isinstance(value, (int, float)): - return unicode(value) + return str(value) elif isinstance(value, str): - return unicode(value, encoding) + return str(value, encoding) else: raise ValueError("unable to convert to unicode: %r" % value)

Here the same test is done twice too.

Modified: python/branches/py3k-struni/Lib/test/pickletester.py ============================================================================== --- python/branches/py3k-struni/Lib/test/pickletester.py (original) +++ python/branches/py3k-struni/Lib/test/pickletester.py Wed May 2 21:09:54 2007 @@ -484,8 +484,8 @@

if haveunicode: def testunicode(self): - endcases = [unicode(''), unicode('<\u>'), unicode('<\\u1234>'), - unicode('<\n>'), unicode('<\>')] + endcases = [str(''), str('<\u>'), str('<\\u1234>'), + str('<\n>'), str('<\>')]

The str() call is unnecessary.

Modified: python/branches/py3k-struni/Lib/test/stringtests.py ============================================================================== --- python/branches/py3k-struni/Lib/test/stringtests.py (original) +++ python/branches/py3k-struni/Lib/test/stringtests.py Wed May 2 21:09:54 2007 @@ -589,7 +589,7 @@ self.checkequal(['a']*19 + ['a '], aaa, 'split', None, 19)

# mixed use of str and unicode - self.checkequal([u'a', u'b', u'c d'], 'a b c d', 'split', u' ', 2) + self.checkequal(['a', 'b', 'c d'], 'a b c d', 'split', ' ', 2) def testadditionalrsplit(self): self.checkequal(['this', 'is', 'the', 'rsplit', 'function'], @@ -622,7 +622,7 @@ self.checkequal([' a a'] + ['a']*18, aaa, 'rsplit', None, 18) # mixed use of str and unicode - self.checkequal([u'a b', u'c', u'd'], 'a b c d', 'rsplit', u' ', 2) + self.checkequal(['a b', 'c', 'd'], 'a b c d', 'rsplit', ' ', 2) def teststrip(self): self.checkequal('hello', ' hello ', 'strip') @@ -644,14 +644,14 @@ # strip/lstrip/rstrip with unicode arg if testsupport.haveunicode: - self.checkequal(unicode('hello', 'ascii'), 'xyzzyhelloxyzzy', - 'strip', unicode('xyz', 'ascii')) - self.checkequal(unicode('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy', - 'lstrip', unicode('xyz', 'ascii')) - self.checkequal(unicode('xyzzyhello', 'ascii'), 'xyzzyhelloxyzzy', - 'rstrip', unicode('xyz', 'ascii')) - self.checkequal(unicode('hello', 'ascii'), 'hello', - 'strip', unicode('xyz', 'ascii')) + self.checkequal(str('hello', 'ascii'), 'xyzzyhelloxyzzy', + 'strip', str('xyz', 'ascii')) + self.checkequal(str('helloxyzzy', 'ascii'), 'xyzzyhelloxyzzy', + 'lstrip', str('xyz', 'ascii')) + self.checkequal(str('xyzzyhello', 'ascii'), 'xyzzyhelloxyzzy', + 'rstrip', str('xyz', 'ascii')) + self.checkequal(str('hello', 'ascii'), 'hello', + 'strip', str('xyz', 'ascii'))

The str() call is unnecessary.

self.checkraises(TypeError, 'hello', 'strip', 42, 42) self.checkraises(TypeError, 'hello', 'lstrip', 42, 42) @@ -908,13 +908,13 @@ self.checkequal(False, '', 'contains', 'asdf') # vereq('asdf' in '', False)

def testsubscript(self): - self.checkequal(u'a', 'abc', 'getitem', 0) - self.checkequal(u'c', 'abc', 'getitem', -1) - self.checkequal(u'a', 'abc', 'getitem', 0) - self.checkequal(u'abc', 'abc', 'getitem', slice(0, 3)) - self.checkequal(u'abc', 'abc', 'getitem', slice(0, 1000)) - self.checkequal(u'a', 'abc', 'getitem', slice(0, 1)) - self.checkequal(u'', 'abc', 'getitem', slice(0, 0)) + self.checkequal('a', 'abc', 'getitem', 0) + self.checkequal('c', 'abc', 'getitem', -1) + self.checkequal('a', 'abc', 'getitem', 0) + self.checkequal('abc', 'abc', 'getitem', slice(0, 3)) + self.checkequal('abc', 'abc', 'getitem', slice(0, 1000)) + self.checkequal('a', 'abc', 'getitem', slice(0, 1)) + self.checkequal('', 'abc', 'getitem', slice(0, 0)) # FIXME What about negative indices? This is handled differently by [] and getitem(slice) self.checkraises(TypeError, 'abc', 'getitem', 'def') @@ -957,11 +957,11 @@ self.checkequal('abc', 'a', 'join', ('abc',)) self.checkequal('z', 'a', 'join', UserList(['z'])) if testsupport.haveunicode: - self.checkequal(unicode('a.b.c'), unicode('.'), 'join', ['a', 'b', 'c']) - self.checkequal(unicode('a.b.c'), '.', 'join', [unicode('a'), 'b', 'c']) - self.checkequal(unicode('a.b.c'), '.', 'join', ['a', unicode('b'), 'c']) - self.checkequal(unicode('a.b.c'), '.', 'join', ['a', 'b', unicode('c')]) - self.checkraises(TypeError, '.', 'join', ['a', unicode('b'), 3]) + self.checkequal(str('a.b.c'), str('.'), 'join', ['a', 'b', 'c']) + self.checkequal(str('a.b.c'), '.', 'join', [str('a'), 'b', 'c']) + self.checkequal(str('a.b.c'), '.', 'join', ['a', str('b'), 'c']) + self.checkequal(str('a.b.c'), '.', 'join', ['a', 'b', str('c')]) + self.checkraises(TypeError, '.', 'join', ['a', str('b'), 3])

The str() call is unnecessary.

Modified: python/branches/py3k-struni/Lib/test/testarray.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testarray.py (original) +++ python/branches/py3k-struni/Lib/test/testarray.py Wed May 2 21:09:54 2007 @@ -747,7 +747,7 @@

def testnounicode(self): a = array.array(self.typecode, self.example) - self.assertRaises(ValueError, a.fromunicode, unicode('')) + self.assertRaises(ValueError, a.fromunicode, str('')) self.assertRaises(ValueError, a.tounicode)

Should the method fromunicode() and tounicode() be renamed?

tests.append(CharacterTest) @@ -755,27 +755,27 @@ if testsupport.haveunicode: class UnicodeTest(StringTest): typecode = 'u' - example = unicode(r'\x01\u263a\x00\ufeff', 'unicode-escape') - smallerexample = unicode(r'\x01\u263a\x00\ufefe', 'unicode-escape') - biggerexample = unicode(r'\x01\u263a\x01\ufeff', 'unicode-escape') - outside = unicode('\x33') + example = str(r'\x01\u263a\x00\ufeff', 'unicode-escape') + smallerexample = str(r'\x01\u263a\x00\ufefe', 'unicode-escape') + biggerexample = str(r'\x01\u263a\x01\ufeff', 'unicode-escape') + outside = str('\x33') minitemsize = 2

def testunicode(self): - self.assertRaises(TypeError, array.array, 'b', unicode('foo', 'ascii')) + self.assertRaises(TypeError, array.array, 'b', str('foo', 'ascii')) - a = array.array('u', unicode(r'\xa0\xc2\u1234', 'unicode-escape')) - a.fromunicode(unicode(' ', 'ascii')) - a.fromunicode(unicode('', 'ascii')) - a.fromunicode(unicode('', 'ascii')) - a.fromunicode(unicode(r'\x11abc\xff\u1234', 'unicode-escape')) + a = array.array('u', str(r'\xa0\xc2\u1234', 'unicode-escape')) + a.fromunicode(str(' ', 'ascii')) + a.fromunicode(str('', 'ascii')) + a.fromunicode(str('', 'ascii')) + a.fromunicode(str(r'\x11abc\xff\u1234', 'unicode-escape')) s = a.tounicode() self.assertEqual( s, - unicode(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape') + str(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape') ) - s = unicode(r'\x00="'a\b\x80\xff\u0000\u0001\u1234', 'unicode-escape') + s = str(r'\x00="'a\b\x80\xff\u0000\u0001\u1234', 'unicode-escape') a = array.array('u', s) self.assertEqual( repr(a),

The str(..., 'ascii') call is unnecessary.

Modified: python/branches/py3k-struni/Lib/test/testbinascii.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testbinascii.py (original) +++ python/branches/py3k-struni/Lib/test/testbinascii.py Wed May 2 21:09:54 2007 @@ -124,7 +124,7 @@

# Verify the treatment of Unicode strings if testsupport.haveunicode: - self.assertEqual(binascii.hexlify(unicode('a', 'ascii')), '61') + self.assertEqual(binascii.hexlify(str('a', 'ascii')), '61')

The str() call is unnecessary.

Modified: python/branches/py3k-struni/Lib/test/testbool.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testbool.py (original) +++ python/branches/py3k-struni/Lib/test/testbool.py Wed May 2 21:09:54 2007 @@ -208,28 +208,28 @@ self.assertIs("xyz".startswith("z"), False)

if testsupport.haveunicode: - self.assertIs(unicode("xyz", 'ascii').endswith(unicode("z", 'ascii')), True) - self.assertIs(unicode("xyz", 'ascii').endswith(unicode("x", 'ascii')), False) - self.assertIs(unicode("xyz0123", 'ascii').isalnum(), True) - self.assertIs(unicode("@#$%", 'ascii').isalnum(), False) - self.assertIs(unicode("xyz", 'ascii').isalpha(), True) - self.assertIs(unicode("@#$%", 'ascii').isalpha(), False) - self.assertIs(unicode("0123", 'ascii').isdecimal(), True) - self.assertIs(unicode("xyz", 'ascii').isdecimal(), False) - self.assertIs(unicode("0123", 'ascii').isdigit(), True) - self.assertIs(unicode("xyz", 'ascii').isdigit(), False) - self.assertIs(unicode("xyz", 'ascii').islower(), True) - self.assertIs(unicode("XYZ", 'ascii').islower(), False) - self.assertIs(unicode("0123", 'ascii').isnumeric(), True) - self.assertIs(unicode("xyz", 'ascii').isnumeric(), False) - self.assertIs(unicode(" ", 'ascii').isspace(), True) - self.assertIs(unicode("XYZ", 'ascii').isspace(), False) - self.assertIs(unicode("X", 'ascii').istitle(), True) - self.assertIs(unicode("x", 'ascii').istitle(), False) - self.assertIs(unicode("XYZ", 'ascii').isupper(), True) - self.assertIs(unicode("xyz", 'ascii').isupper(), False) - self.assertIs(unicode("xyz", 'ascii').startswith(unicode("x", 'ascii')), True) - self.assertIs(unicode("xyz", 'ascii').startswith(unicode("z", 'ascii')), False) + self.assertIs(str("xyz", 'ascii').endswith(str("z", 'ascii')), True) + self.assertIs(str("xyz", 'ascii').endswith(str("x", 'ascii')), False) + self.assertIs(str("xyz0123", 'ascii').isalnum(), True) + self.assertIs(str("@#$%", 'ascii').isalnum(), False) + self.assertIs(str("xyz", 'ascii').isalpha(), True) + self.assertIs(str("@#$%", 'ascii').isalpha(), False) + self.assertIs(str("0123", 'ascii').isdecimal(), True) + self.assertIs(str("xyz", 'ascii').isdecimal(), False) + self.assertIs(str("0123", 'ascii').isdigit(), True) + self.assertIs(str("xyz", 'ascii').isdigit(), False) + self.assertIs(str("xyz", 'ascii').islower(), True) + self.assertIs(str("XYZ", 'ascii').islower(), False) + self.assertIs(str("0123", 'ascii').isnumeric(), True) + self.assertIs(str("xyz", 'ascii').isnumeric(), False) + self.assertIs(str(" ", 'ascii').isspace(), True) + self.assertIs(str("XYZ", 'ascii').isspace(), False) + self.assertIs(str("X", 'ascii').istitle(), True) + self.assertIs(str("x", 'ascii').istitle(), False) + self.assertIs(str("XYZ", 'ascii').isupper(), True) + self.assertIs(str("xyz", 'ascii').isupper(), False) + self.assertIs(str("xyz", 'ascii').startswith(str("x", 'ascii')), True) + self.assertIs(str("xyz", 'ascii').startswith(str("z", 'ascii')), False)

These tests can IMHO simply be dropped.

Modified: python/branches/py3k-struni/Lib/test/testbuiltin.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testbuiltin.py (original) +++ python/branches/py3k-struni/Lib/test/testbuiltin.py Wed May 2 21:09:54 2007 @@ -74,22 +74,22 @@ ] if haveunicode: L += [ - (unicode('0'), 0), - (unicode('1'), 1), - (unicode('9'), 9), - (unicode('10'), 10), - (unicode('99'), 99), - (unicode('100'), 100), - (unicode('314'), 314), - (unicode(' 314'), 314), - (unicode(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314), - (unicode(' \t\t 314 \t\t '), 314), - (unicode(' 1x'), ValueError), - (unicode(' 1 '), 1), - (unicode(' 1\02 '), ValueError), - (unicode(''), ValueError), - (unicode(' '), ValueError), - (unicode(' \t\t '), ValueError), + (str('0'), 0), + (str('1'), 1), + (str('9'), 9), + (str('10'), 10), + (str('99'), 99), + (str('100'), 100), + (str('314'), 314), + (str(' 314'), 314), + (str(b'\u0663\u0661\u0664 ','raw-unicode-escape'), 314), + (str(' \t\t 314 \t\t '), 314), + (str(' 1x'), ValueError), + (str(' 1 '), 1), + (str(' 1\02 '), ValueError), + (str(''), ValueError), + (str(' '), ValueError), + (str(' \t\t '), ValueError), (unichr(0x200), ValueError), ]

Most of these tests can probably be dropped too.

Probably any test that checks have_unicode should be looked at.

Modified: python/branches/py3k-struni/Lib/test/testcfgparser.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testcfgparser.py (original) +++ python/branches/py3k-struni/Lib/test/testcfgparser.py Wed May 2 21:09:54 2007 @@ -248,12 +248,12 @@ cf.set("sect", "option2", "splat") cf.set("sect", "option2", mystr("splat")) try: - unicode + str except NameError: pass else: - cf.set("sect", "option1", unicode("splat")) - cf.set("sect", "option2", unicode("splat")) + cf.set("sect", "option1", str("splat")) + cf.set("sect", "option2", str("splat"))

The try:except: and the str() call is unnecessary.

Modified: python/branches/py3k-struni/Lib/test/testcharmapcodec.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testcharmapcodec.py (original) +++ python/branches/py3k-struni/Lib/test/testcharmapcodec.py Wed May 2 21:09:54 2007 @@ -27,27 +27,27 @@

class CharmapCodecTest(unittest.TestCase): def testconstructorx(self): - self.assertEquals(unicode('abc', codecname), u'abc') - self.assertEquals(unicode('xdef', codecname), u'abcdef') - self.assertEquals(unicode('defx', codecname), u'defabc') - self.assertEquals(unicode('dxf', codecname), u'dabcf') - self.assertEquals(unicode('dxfx', codecname), u'dabcfabc') + self.assertEquals(str('abc', codecname), 'abc') + self.assertEquals(str('xdef', codecname), 'abcdef') + self.assertEquals(str('defx', codecname), 'defabc') + self.assertEquals(str('dxf', codecname), 'dabcf') + self.assertEquals(str('dxfx', codecname), 'dabcfabc') def testencodex(self): - self.assertEquals(u'abc'.encode(codecname), 'abc') - self.assertEquals(u'xdef'.encode(codecname), 'abcdef') - self.assertEquals(u'defx'.encode(codecname), 'defabc') - self.assertEquals(u'dxf'.encode(codecname), 'dabcf') - self.assertEquals(u'dxfx'.encode(codecname), 'dabcfabc') + self.assertEquals('abc'.encode(codecname), 'abc') + self.assertEquals('xdef'.encode(codecname), 'abcdef') + self.assertEquals('defx'.encode(codecname), 'defabc') + self.assertEquals('dxf'.encode(codecname), 'dabcf') + self.assertEquals('dxfx'.encode(codecname), 'dabcfabc') def testconstructory(self): - self.assertEquals(unicode('ydef', codecname), u'def') - self.assertEquals(unicode('defy', codecname), u'def') - self.assertEquals(unicode('dyf', codecname), u'df') - self.assertEquals(unicode('dyfy', codecname), u'df') + self.assertEquals(str('ydef', codecname), 'def') + self.assertEquals(str('defy', codecname), 'def') + self.assertEquals(str('dyf', codecname), 'df') + self.assertEquals(str('dyfy', codecname), 'df')

These should probably be b'...' constants.

Modified: python/branches/py3k-struni/Lib/test/testcomplex.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testcomplex.py (original) +++ python/branches/py3k-struni/Lib/test/testcomplex.py Wed May 2 21:09:54 2007 @@ -227,7 +227,7 @@

self.assertEqual(complex(" 3.14+J "), 3.14+1j) if testsupport.haveunicode: - self.assertEqual(complex(unicode(" 3.14+J ")), 3.14+1j) + self.assertEqual(complex(str(" 3.14+J ")), 3.14+1j) # SF bug 543840: complex(string) accepts strings with \0 # Fixed in 2.3. @@ -251,8 +251,8 @@ self.assertRaises(ValueError, complex, "1+(2j)") self.assertRaises(ValueError, complex, "(1+2j)123") if testsupport.haveunicode: - self.assertRaises(ValueError, complex, unicode("1"*500)) - self.assertRaises(ValueError, complex, unicode("x")) + self.assertRaises(ValueError, complex, str("1"*500)) + self.assertRaises(ValueError, complex, str("x"))

The str() calls are unnecessary.

Modified: python/branches/py3k-struni/Lib/test/testcontains.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testcontains.py (original) +++ python/branches/py3k-struni/Lib/test/testcontains.py Wed May 2 21:09:54 2007 @@ -59,31 +59,31 @@

# Test char in Unicode - check('c' in unicode('abc'), "'c' not in u'abc'") - check('d' not in unicode('abc'), "'d' in u'abc'") + check('c' in str('abc'), "'c' not in u'abc'") + check('d' not in str('abc'), "'d' in u'abc'") - check('' in unicode(''), "'' not in u''") - check(unicode('') in '', "u'' not in ''") - check(unicode('') in unicode(''), "u'' not in u''") - check('' in unicode('abc'), "'' not in u'abc'") - check(unicode('') in 'abc', "u'' not in 'abc'") - check(unicode('') in unicode('abc'), "u'' not in u'abc'") + check('' in str(''), "'' not in u''") + check(str('') in '', "u'' not in ''") + check(str('') in str(''), "u'' not in u''") + check('' in str('abc'), "'' not in u'abc'") + check(str('') in 'abc', "u'' not in 'abc'") + check(str('') in str('abc'), "u'' not in u'abc'") try: - None in unicode('abc') + None in str('abc') check(0, "None in u'abc' did not raise error") except TypeError: pass # Test Unicode char in Unicode - check(unicode('c') in unicode('abc'), "u'c' not in u'abc'") - check(unicode('d') not in unicode('abc'), "u'd' in u'abc'") + check(str('c') in str('abc'), "u'c' not in u'abc'") + check(str('d') not in str('abc'), "u'd' in u'abc'")

The str() calls are unnecessary.

# Test Unicode char in string

- check(unicode('c') in 'abc', "u'c' not in 'abc'") - check(unicode('d') not in 'abc', "u'd' in 'abc'") + check(str('c') in 'abc', "u'c' not in 'abc'") + check(str('d') not in 'abc', "u'd' in 'abc'")

This is testing the same as above.

Modified: python/branches/py3k-struni/Lib/test/testdescr.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testdescr.py (original) +++ python/branches/py3k-struni/Lib/test/testdescr.py Wed May 2 21:09:54 2007 @@ -264,7 +264,7 @@ del junk

# Just make sure these don't blow up! - for arg in 2, 2, 2j, 2e0, [2], "2", u"2", (2,), {2:2}, type, testdir: + for arg in 2, 2, 2j, 2e0, [2], "2", "2", (2,), {2:2}, type, testdir:

This tests "2" twice.

dir(arg)

# Test dir on custom classes. Since these have object as a @@ -1100,25 +1100,25 @@ # Test unicode slot names try: - unicode + str except NameError: pass

The try:except: is be unnecessary.

else: # Test a single unicode string is not expanded as a sequence. class C(object): - slots = unicode("abc") + slots = str("abc")

The str() call is unnecessary.

c = C() c.abc = 5 vereq(c.abc, 5)

# unicodetostring used to modify slots in certain circumstances - slots = (unicode("foo"), unicode("bar")) + slots = (str("foo"), str("bar"))

The str() calls are unnecessary.

class C(object): slots = slots x = C() x.foo = 5 vereq(x.foo, 5) - veris(type(slots[0]), unicode) + veris(type(slots[0]), str) # this used to leak references try: class C(object): @@ -2301,64 +2301,64 @@ [...] class sublist(list): pass @@ -2437,12 +2437,12 @@ vereq(int(x=3), 3) vereq(complex(imag=42, real=666), complex(666, 42)) vereq(str(object=500), '500') - vereq(unicode(string='abc', errors='strict'), u'abc') + vereq(str(string='abc', errors='strict'), 'abc') vereq(tuple(sequence=range(3)), (0, 1, 2)) vereq(list(sequence=(0, 1, 2)), range(3)) # note: as of Python 2.3, dict() no longer has an "items" keyword arg

- for constructor in (int, float, int, complex, str, unicode, + for constructor in (int, float, int, complex, str, str, tuple, list, file): try: constructor(boguskeywordarg=1) @@ -2719,13 +2719,13 @@ class H(object): slots = ["b", "a"] try: - unicode + str

The try:except: is unnecessary.

except NameError: class I(object): slots = ["a", "b"] else: class I(object): - slots = [unicode("a"), unicode("b")] + slots = [str("a"), str("b")] class J(object): slots = ["c", "b"] class K(object): @@ -3124,9 +3124,9 @@

# It's not clear that unicode will continue to support the character # buffer interface, and this test will fail if that's taken away. - class MyUni(unicode): + class MyUni(str): pass - base = u'abc' + base = 'abc' m = MyUni(base) vereq(binascii.b2ahex(m), binascii.b2ahex(base))

Modified: python/branches/py3k-struni/Lib/test/testfile.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testfile.py (original) +++ python/branches/py3k-struni/Lib/test/testfile.py Wed May 2 21:09:54 2007 @@ -145,7 +145,7 @@

def testUnicodeOpen(self): # verify repr works for unicode too - f = open(unicode(TESTFN), "w") + f = open(str(TESTFN), "w") self.assert(repr(f).startswith("<open file u'" + TESTFN))

This test might fail, because the u prefix is gone.

Modified: python/branches/py3k-struni/Lib/test/testformat.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testformat.py (original) +++ python/branches/py3k-struni/Lib/test/testformat.py Wed May 2 21:09:54 2007 @@ -35,7 +35,7 @@ def testboth(formatstr, *args): testformat(formatstr, *args) if haveunicode: - testformat(unicode(formatstr), *args) + testformat(str(formatstr), *args)

This is the same test twice.

Modified: python/branches/py3k-struni/Lib/test/testiter.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testiter.py (original) +++ python/branches/py3k-struni/Lib/test/testiter.py Wed May 2 21:09:54 2007 @@ -216,9 +216,9 @@ # Test a Unicode string if haveunicode: def testiterunicode(self): - self.checkforloop(iter(unicode("abcde")), - [unicode("a"), unicode("b"), unicode("c"), - unicode("d"), unicode("e")]) + self.checkforloop(iter(str("abcde")), + [str("a"), str("b"), str("c"), + str("d"), str("e")])

The str() calls are unnecessary.

# Test a directory def testiterdict(self): @@ -518,7 +518,7 @@ i = self.i self.i = i+1 if i == 2: - return unicode("fooled you!") + return str("fooled you!")

The str() call is unnecessary.

return next(self.it)

f = open(TESTFN, "w") @@ -535,7 +535,7 @@ # and pass that on to unicode.join(). try: got = " - ".join(OhPhooey(f)) - self.assertEqual(got, unicode("a\n - b\n - fooled you! - c\n")) + self.assertEqual(got, str("a\n - b\n - fooled you! - c\n"))

The str() call is unnecessary.

Modified: python/branches/py3k-struni/Lib/test/testpep352.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testpep352.py (original) +++ python/branches/py3k-struni/Lib/test/testpep352.py Wed May 2 21:09:54 2007 @@ -90,7 +90,7 @@ arg = "spam" exc = Exception(arg) results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg], - [str(exc), str(arg)], [unicode(exc), unicode(arg)], + [str(exc), str(arg)], [str(exc), str(arg)], [repr(exc), exc.class.name + repr(exc.args)]) self.interfacetestdriver(results)

@@ -101,7 +101,7 @@ exc = Exception(*args) results = ([len(exc.args), argcount], [exc.args, args], [exc.message, ''], [str(exc), str(args)], - [unicode(exc), unicode(args)], + [str(exc), str(args)], [repr(exc), exc.class.name + repr(exc.args)]) self.interfacetestdriver(results) @@ -109,7 +109,7 @@ # Make sure that with no args that interface is correct exc = Exception() results = ([len(exc.args), 0], [exc.args, tuple()], [exc.message, ''], - [str(exc), ''], [unicode(exc), u''], + [str(exc), ''], [str(exc), ''], [repr(exc), exc.class.name + '()']) self.interfacetestdriver(results)

Seems like here the same test is done twice too.

Modified: python/branches/py3k-struni/Lib/test/testpprint.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testpprint.py (original) +++ python/branches/py3k-struni/Lib/test/testpprint.py Wed May 2 21:09:54 2007 @@ -3,7 +3,7 @@ import unittest

try: - uni = unicode + uni = str except NameError: def uni(x): return x

This can be simplyfied to uni = str (or use str everywhere)

Modified: python/branches/py3k-struni/Lib/test/testre.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testre.py (original) +++ python/branches/py3k-struni/Lib/test/testre.py Wed May 2 21:09:54 2007 @@ -324,12 +324,12 @@ [...] def teststackoverflow(self): @@ -561,10 +561,10 @@ def testbug764548(self): # bug 764548, re.compile() barfs on str/unicode subclasses try: - unicode + str except NameError: return # no problem if we have no unicode

The try:except: can be removed.

- class myunicode(unicode): pass + class myunicode(str): pass pat = re.compile(myunicode("abc")) self.assertEqual(pat.match("xyz"), None)

@@ -575,7 +575,7 @@ def testbug926075(self): try: - unicode + str except NameError: return # no problem if we have no unicode self.assert(re.compile('bug926075') is not

The try:except: can be removed.

@@ -583,7 +583,7 @@

def testbug931848(self): try: - unicode + str except NameError: pass pattern = eval('u"[\u002E\u3002\uFF0E\uFF61]"')

The try:except: can be removed.

Modified: python/branches/py3k-struni/Lib/test/testset.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testset.py (original) +++ python/branches/py3k-struni/Lib/test/testset.py Wed May 2 21:09:54 2007 @@ -72,7 +72,7 @@ self.assertEqual(type(u), self.thetype) self.assertRaises(PassThru, self.s.union, checkpassthru()) self.assertRaises(TypeError, self.s.union, [[]]) - for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: + for C in set, frozenset, dict.fromkeys, str, str, list, tuple:

This tests str twice. (This happends several times in test_set.py

self.assertEqual(self.thetype('abcba').union(C('cdc')), set('abcd')) self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg')) self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc')) [...]

Modified: python/branches/py3k-struni/Lib/test/teststr.py ============================================================================== --- python/branches/py3k-struni/Lib/test/teststr.py (original) +++ python/branches/py3k-struni/Lib/test/teststr.py Wed May 2 21:09:54 2007 @@ -31,7 +31,7 @@ # Make sure str() behaves properly class Foo0: def unicode(self):

What happens with unicode after unification?

Modified: python/branches/py3k-struni/Lib/test/testsupport.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testsupport.py (original) +++ python/branches/py3k-struni/Lib/test/testsupport.py Wed May 2 21:09:54 2007 @@ -131,7 +131,7 @@ return (x > y) - (x < y)

try: - unicode + str haveunicode = True except NameError: haveunicode = False

Can this be dropped?

@@ -151,13 +151,13 @@ # Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding() # TESTFNUNICODE is a filename that can be encoded using the # file system encoding, but not with the default (ascii) encoding - if isinstance('', unicode): + if isinstance('', str): # python -U # XXX perhaps unicode() should accept Unicode strings? TESTFNUNICODE = "@test-\xe0\xf2" else: # 2 latin characters. - TESTFNUNICODE = unicode("@test-\xe0\xf2", "latin-1") + TESTFNUNICODE = str("@test-\xe0\xf2", "latin-1") TESTFNENCODING = sys.getfilesystemencoding() # TESTFNUNICODEUNENCODEABLE is a filename that should not be # able to be encoded by either the default or filesystem encoding.

Modified: python/branches/py3k-struni/Lib/test/testunicode.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testunicode.py (original) +++ python/branches/py3k-struni/Lib/test/testunicode.py Wed May 2 21:09:54 2007

This should probably be dropped/merged into test_str.

Modified: python/branches/py3k-struni/Lib/test/testxmlrpc.py ============================================================================== --- python/branches/py3k-struni/Lib/test/testxmlrpc.py (original) +++ python/branches/py3k-struni/Lib/test/testxmlrpc.py Wed May 2 21:09:54 2007 @@ -5,7 +5,7 @@ from test import testsupport

try: - unicode + str except NameError: haveunicode = False

The try:except: can be dropped.

Modified: python/branches/py3k-struni/Lib/textwrap.py ============================================================================== --- python/branches/py3k-struni/Lib/textwrap.py (original) +++ python/branches/py3k-struni/Lib/textwrap.py Wed May 2 21:09:54 2007 @@ -70,7 +70,7 @@ whitespacetrans = string.maketrans(whitespace, ' ' * len(whitespace))

unicodewhitespacetrans = {} - uspace = ord(u' ') + uspace = ord(' ') for x in map(ord, whitespace): unicodewhitespacetrans[x] = uspace @@ -127,7 +127,7 @@ if self.replacewhitespace: if isinstance(text, str): text = text.translate(self.whitespacetrans) - elif isinstance(text, unicode): + elif isinstance(text, str):

This checks for str twice.

Modified: python/branches/py3k-struni/Lib/types.py ============================================================================== --- python/branches/py3k-struni/Lib/types.py (original) +++ python/branches/py3k-struni/Lib/types.py Wed May 2 21:09:54 2007 @@ -28,7 +28,7 @@ # types.StringTypes", you should use "isinstance(x, basestring)". But # we keep around for compatibility with Python 2.2. try: - UnicodeType = unicode + UnicodeType = str StringTypes = (StringType, UnicodeType) except NameError: StringTypes = (StringType,)

Can we drop this?

Modified: python/branches/py3k-struni/Lib/urllib.py ============================================================================== --- python/branches/py3k-struni/Lib/urllib.py (original) +++ python/branches/py3k-struni/Lib/urllib.py Wed May 2 21:09:54 2007 @@ -984,13 +984,13 @@ # quote('abc def') -> 'abc%20def')

try: - unicode + str except NameError: def isunicode(x): return 0 else: def isunicode(x): - return isinstance(x, unicode) + return isinstance(x, str)

Can _is_unicode simply return True?

Modified: python/branches/py3k-struni/Lib/xml/dom/minicompat.py ============================================================================== --- python/branches/py3k-struni/Lib/xml/dom/minicompat.py (original) +++ python/branches/py3k-struni/Lib/xml/dom/minicompat.py Wed May 2 21:09:54 2007 @@ -41,11 +41,11 @@ import xml.dom

try: - unicode + str except NameError: StringTypes = type(''), else: - StringTypes = type(''), type(unicode('')) + StringTypes = type(''), type(str(''))

This ammounts to StringTypes = str

class NodeList(list):

Modified: python/branches/py3k-struni/Lib/xmlrpclib.py ============================================================================== --- python/branches/py3k-struni/Lib/xmlrpclib.py (original) +++ python/branches/py3k-struni/Lib/xmlrpclib.py Wed May 2 21:09:54 2007 @@ -144,9 +144,9 @@ # Internal stuff try: - unicode + str except NameError: - unicode = None # unicode support not available + str = None # unicode support not available

The try:except: can be dropped and all subsequent "if str:" tests too.



More information about the Python-3000 mailing list