[Python-3000] [Python-checkins] r55079 - in python/branches/py3k-struni/Lib: [many files]
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] = _deepcopy_atomic
> try:
> - d[unicode] = _deepcopy_atomic
> + d[str] = _deepcopy_atomic
> 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 @@
> create_string_buffer(anInteger) -> character array
> create_string_buffer(aString, anInteger) -> character array
> """
> - if isinstance(init, (str, unicode)):
> + if isinstance(init, (str, str)):
> if size is None:
> size = len(init)+1
> buftype = c_char * size
> @@ -281,7 +281,7 @@
> create_unicode_buffer(anInteger) -> character array
> create_unicode_buffer(aString, anInteger) -> character array
> """
> - if isinstance(init, (str, unicode)):
> + if isinstance(init, (str, str)):
> if size is None:
> size = len(init)+1
> buftype = c_wchar * size
This could be simplyfied to:
if isinstance(init, str):
> Modified: python/branches/py3k-struni/Lib/distutils/command/bdist_wininst.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/distutils/command/bdist_wininst.py (original)
> +++ python/branches/py3k-struni/Lib/distutils/command/bdist_wininst.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 ucd_3_2_0 as unicodedata
>
> # IDNA section 3.1
> -dots = re.compile(u"[\u002E\u3002\uFF0E\uFF61]")
> +dots = re.compile("[\u002E\u3002\uFF0E\uFF61]")
>
> # IDNA section 5
> ace_prefix = "xn--"
> -uace_prefix = unicode(ace_prefix, "ascii")
> +uace_prefix = str(ace_prefix, "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.selection_fsr[0].as_pathname())
> - if issubclass(tpwanted, unicode):
> + if issubclass(tpwanted, str):
> return tpwanted(rr.selection_fsr[0].as_pathname(), '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].as_pathname()
> else:
> @@ -722,10 +722,10 @@
> pardir_fss = Carbon.File.FSSpec((vrefnum, dirid, ''))
> pardir_fsr = Carbon.File.FSRef(pardir_fss)
> pardir_path = pardir_fsr.FSRefMakePath() # This is utf-8
> - name_utf8 = unicode(name, 'macroman').encode('utf8')
> + name_utf8 = str(name, 'macroman').encode('utf8')
> fullpath = os.path.join(pardir_path, name_utf8)
> - 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.selection_fsr[0].as_pathname())
> - 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.text_factory = 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):
> - pax_headers[name] = unicode(val)
> + pax_headers[name] = str(val)
> info[name] = 0
>
> if pax_headers:
> @@ -1054,12 +1054,12 @@
>
> @staticmethod
> def _to_unicode(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 have_unicode:
> def test_unicode(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/string_tests.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/string_tests.py (original)
> +++ python/branches/py3k-struni/Lib/test/string_tests.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 test_additional_rsplit(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 test_strip(self):
> self.checkequal('hello', ' hello ', 'strip')
> @@ -644,14 +644,14 @@
>
> # strip/lstrip/rstrip with unicode arg
> if test_support.have_unicode:
> - 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 test_subscript(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 test_support.have_unicode:
> - 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/test_array.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_array.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_array.py Wed May 2 21:09:54 2007
> @@ -747,7 +747,7 @@
>
> def test_nounicode(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 test_support.have_unicode:
> 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 test_unicode(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/test_binascii.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_binascii.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_binascii.py Wed May 2 21:09:54 2007
> @@ -124,7 +124,7 @@
>
> # Verify the treatment of Unicode strings
> if test_support.have_unicode:
> - 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/test_bool.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_bool.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_bool.py Wed May 2 21:09:54 2007
> @@ -208,28 +208,28 @@
> self.assertIs("xyz".startswith("z"), False)
>
> if test_support.have_unicode:
> - 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/test_builtin.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_builtin.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_builtin.py Wed May 2 21:09:54 2007
> @@ -74,22 +74,22 @@
> ]
> if have_unicode:
> 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/test_cfgparser.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_cfgparser.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_cfgparser.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/test_charmapcodec.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_charmapcodec.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_charmapcodec.py Wed May 2 21:09:54 2007
> @@ -27,27 +27,27 @@
>
> class CharmapCodecTest(unittest.TestCase):
> def test_constructorx(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 test_encodex(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 test_constructory(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/test_complex.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_complex.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_complex.py Wed May 2 21:09:54 2007
> @@ -227,7 +227,7 @@
>
> self.assertEqual(complex(" 3.14+J "), 3.14+1j)
> if test_support.have_unicode:
> - 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 test_support.have_unicode:
> - 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/test_contains.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_contains.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_contains.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/test_descr.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_descr.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_descr.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, test_dir:
> + for arg in 2, 2, 2j, 2e0, [2], "2", "2", (2,), {2:2}, type, test_dir:
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)
>
> # _unicode_to_string 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(bogus_keyword_arg=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.b2a_hex(m), binascii.b2a_hex(base))
> Modified: python/branches/py3k-struni/Lib/test/test_file.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_file.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_file.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/test_format.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_format.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_format.py Wed May 2 21:09:54 2007
> @@ -35,7 +35,7 @@
> def testboth(formatstr, *args):
> testformat(formatstr, *args)
> if have_unicode:
> - testformat(unicode(formatstr), *args)
> + testformat(str(formatstr), *args)
This is the same test twice.
> Modified: python/branches/py3k-struni/Lib/test/test_iter.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_iter.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_iter.py Wed May 2 21:09:54 2007
> @@ -216,9 +216,9 @@
> # Test a Unicode string
> if have_unicode:
> def test_iter_unicode(self):
> - self.check_for_loop(iter(unicode("abcde")),
> - [unicode("a"), unicode("b"), unicode("c"),
> - unicode("d"), unicode("e")])
> + self.check_for_loop(iter(str("abcde")),
> + [str("a"), str("b"), str("c"),
> + str("d"), str("e")])
The str() calls are unnecessary.
> # Test a directory
> def test_iter_dict(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/test_pep352.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_pep352.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_pep352.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.interface_test_driver(results)
>
> @@ -101,7 +101,7 @@
> exc = Exception(*args)
> results = ([len(exc.args), arg_count], [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.interface_test_driver(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.interface_test_driver(results)
Seems like here the same test is done twice too.
> Modified: python/branches/py3k-struni/Lib/test/test_pprint.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_pprint.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_pprint.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/test_re.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_re.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_re.py Wed May 2 21:09:54 2007
> @@ -324,12 +324,12 @@
> [...]
> def test_stack_overflow(self):
> @@ -561,10 +561,10 @@
> def test_bug_764548(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 my_unicode(unicode): pass
> + class my_unicode(str): pass
> pat = re.compile(my_unicode("abc"))
> self.assertEqual(pat.match("xyz"), None)
>
> @@ -575,7 +575,7 @@
>
> def test_bug_926075(self):
> try:
> - unicode
> + str
> except NameError:
> return # no problem if we have no unicode
> self.assert_(re.compile('bug_926075') is not
The try:except: can be removed.
> @@ -583,7 +583,7 @@
>
> def test_bug_931848(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/test_set.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_set.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_set.py Wed May 2 21:09:54 2007
> @@ -72,7 +72,7 @@
> self.assertEqual(type(u), self.thetype)
> self.assertRaises(PassThru, self.s.union, check_pass_thru())
> 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/test_str.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_str.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_str.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/test_support.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_support.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_support.py Wed May 2 21:09:54 2007
> @@ -131,7 +131,7 @@
> return (x > y) - (x < y)
>
> try:
> - unicode
> + str
> have_unicode = True
> except NameError:
> have_unicode = False
Can this be dropped?
> @@ -151,13 +151,13 @@
> # Assuming sys.getfilesystemencoding()!=sys.getdefaultencoding()
> # TESTFN_UNICODE 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?
> TESTFN_UNICODE = "@test-\xe0\xf2"
> else:
> # 2 latin characters.
> - TESTFN_UNICODE = unicode("@test-\xe0\xf2", "latin-1")
> + TESTFN_UNICODE = str("@test-\xe0\xf2", "latin-1")
> TESTFN_ENCODING = sys.getfilesystemencoding()
> # TESTFN_UNICODE_UNENCODEABLE 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/test_unicode.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_unicode.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_unicode.py Wed May 2 21:09:54 2007
This should probably be dropped/merged into test_str.
> Modified: python/branches/py3k-struni/Lib/test/test_xmlrpc.py
> ==============================================================================
> --- python/branches/py3k-struni/Lib/test/test_xmlrpc.py (original)
> +++ python/branches/py3k-struni/Lib/test/test_xmlrpc.py Wed May 2 21:09:54 2007
> @@ -5,7 +5,7 @@
> from test import test_support
>
> try:
> - unicode
> + str
> except NameError:
> have_unicode = 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 @@
> whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
>
> unicode_whitespace_trans = {}
> - uspace = ord(u' ')
> + uspace = ord(' ')
> for x in map(ord, _whitespace):
> unicode_whitespace_trans[x] = uspace
>
> @@ -127,7 +127,7 @@
> if self.replace_whitespace:
> if isinstance(text, str):
> text = text.translate(self.whitespace_trans)
> - 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 _is_unicode(x):
> return 0
> else:
> def _is_unicode(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