summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-16 18:12:55 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-16 18:12:55 (GMT)
commit3172c5d263eeffff1e89d03d79be3ccc1d60fbde (patch)
treea35e103b36b684c4682ded57236199d6a0ecee4b
parent60d241f135f10312f5a638846659d7e471f6cac9 (diff)
downloadcpython-3172c5d263eeffff1e89d03d79be3ccc1d60fbde.zip
cpython-3172c5d263eeffff1e89d03d79be3ccc1d60fbde.tar.gz
cpython-3172c5d263eeffff1e89d03d79be3ccc1d60fbde.tar.bz2
Patch# 1258 by Christian Heimes: kill basestring.
I like this because it makes the code shorter! :-)
-rw-r--r--Include/stringobject.h1
-rw-r--r--Lib/ConfigParser.py4
-rwxr-xr-xLib/UserString.py10
-rw-r--r--Lib/_abcoll.py3
-rw-r--r--Lib/binhex.py4
-rwxr-xr-xLib/cProfile.py2
-rw-r--r--Lib/cmd.py2
-rw-r--r--Lib/cookielib.py2
-rw-r--r--Lib/copy_reg.py2
-rw-r--r--Lib/decimal.py2
-rw-r--r--Lib/distutils/ccompiler.py12
-rw-r--r--Lib/distutils/cmd.py8
-rw-r--r--Lib/distutils/command/build_clib.py4
-rw-r--r--Lib/distutils/command/build_ext.py10
-rw-r--r--Lib/distutils/command/build_py.py2
-rw-r--r--Lib/distutils/command/config.py8
-rw-r--r--Lib/distutils/command/install.py2
-rw-r--r--Lib/distutils/command/install_data.py2
-rw-r--r--Lib/distutils/dir_util.py2
-rw-r--r--Lib/distutils/dist.py6
-rw-r--r--Lib/distutils/extension.py4
-rw-r--r--Lib/distutils/fancy_getopt.py4
-rw-r--r--Lib/distutils/filelist.py2
-rw-r--r--Lib/distutils/unixccompiler.py2
-rw-r--r--Lib/doctest.py10
-rw-r--r--Lib/email/feedparser.py2
-rw-r--r--Lib/email/generator.py6
-rw-r--r--Lib/email/iterators.py2
-rw-r--r--Lib/fileinput.py2
-rw-r--r--Lib/inspect.py2
-rw-r--r--Lib/io.py10
-rw-r--r--Lib/lib-tk/Tkinter.py2
-rw-r--r--Lib/locale.py3
-rw-r--r--Lib/logging/__init__.py2
-rw-r--r--Lib/msilib/__init__.py2
-rw-r--r--Lib/optparse.py9
-rw-r--r--Lib/os.py2
-rw-r--r--Lib/pickle.py2
-rw-r--r--Lib/pickletools.py10
-rw-r--r--Lib/pkgutil.py2
-rw-r--r--Lib/pstats.py2
-rw-r--r--Lib/shlex.py6
-rwxr-xr-xLib/smtplib.py2
-rw-r--r--Lib/sre_compile.py2
-rw-r--r--Lib/subprocess.py4
-rw-r--r--Lib/tarfile.py4
-rw-r--r--Lib/test/test___future__.py2
-rw-r--r--Lib/test/test_abc.py4
-rw-r--r--Lib/test/test_ast.py2
-rw-r--r--Lib/test/test_codeccallbacks.py6
-rw-r--r--Lib/test/test_codecs.py5
-rw-r--r--Lib/test/test_collections.py4
-rwxr-xr-xLib/test/test_grp.py4
-rw-r--r--Lib/test/test_isinstance.py2
-rw-r--r--Lib/test/test_posixpath.py6
-rw-r--r--Lib/test/test_pwd.py10
-rw-r--r--Lib/test/test_re.py7
-rw-r--r--Lib/test/test_support.py2
-rw-r--r--Lib/test/test_sys.py14
-rw-r--r--Lib/test/test_tempfile.py6
-rw-r--r--Lib/test/test_textwrap.py2
-rw-r--r--Lib/test/test_unittest.py4
-rw-r--r--Lib/timeit.py6
-rw-r--r--Lib/unittest.py2
-rw-r--r--Lib/urllib2.py4
-rwxr-xr-xLib/uu.py12
-rw-r--r--Lib/warnings.py4
-rw-r--r--Lib/wave.py4
-rw-r--r--Lib/webbrowser.py2
-rw-r--r--Lib/xml/dom/pulldom.py2
-rw-r--r--Lib/xml/sax/saxutils.py2
-rw-r--r--Lib/xmlrpclib.py6
-rw-r--r--Lib/zipfile.py2
-rw-r--r--Modules/_csv.c2
-rw-r--r--Objects/stringobject.c58
-rw-r--r--Objects/unicodeobject.c4
-rw-r--r--Python/bltinmodule.c10
77 files changed, 171 insertions, 217 deletions
diff --git a/Include/stringobject.h b/Include/stringobject.h
index c6ae1a8..103a9be 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -48,7 +48,6 @@ typedef struct {
*/
} PyStringObject;
-PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyString_Type;
#define PyString_Check(op) \
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
index faa0930..167b963 100644
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -271,7 +271,7 @@ class RawConfigParser:
Return list of successfully read files.
"""
- if isinstance(filenames, basestring):
+ if isinstance(filenames, str):
filenames = [filenames]
read_ok = []
for filename in filenames:
@@ -652,7 +652,7 @@ class SafeConfigParser(ConfigParser):
def set(self, section, option, value):
"""Set an option. Extend ConfigParser.set: check for string values."""
- if not isinstance(value, basestring):
+ if not isinstance(value, str):
raise TypeError("option values must be strings")
# check for bad percent signs:
# first, replace all "good" interpolations
diff --git a/Lib/UserString.py b/Lib/UserString.py
index 8417be7..a11717c 100755
--- a/Lib/UserString.py
+++ b/Lib/UserString.py
@@ -11,7 +11,7 @@ __all__ = ["UserString","MutableString"]
class UserString:
def __init__(self, seq):
- if isinstance(seq, basestring):
+ if isinstance(seq, str):
self.data = seq
elif isinstance(seq, UserString):
self.data = seq.data[:]
@@ -66,12 +66,12 @@ class UserString:
def __add__(self, other):
if isinstance(other, UserString):
return self.__class__(self.data + other.data)
- elif isinstance(other, basestring):
+ elif isinstance(other, str):
return self.__class__(self.data + other)
else:
return self.__class__(self.data + str(other))
def __radd__(self, other):
- if isinstance(other, basestring):
+ if isinstance(other, str):
return self.__class__(other + self.data)
else:
return self.__class__(str(other) + self.data)
@@ -184,7 +184,7 @@ class MutableString(UserString):
if isinstance(index, slice):
if isinstance(sub, UserString):
sub = sub.data
- elif not isinstance(sub, basestring):
+ elif not isinstance(sub, str):
sub = str(sub)
start, stop, step = index.indices(len(self.data))
if step == -1:
@@ -221,7 +221,7 @@ class MutableString(UserString):
def __iadd__(self, other):
if isinstance(other, UserString):
self.data += other.data
- elif isinstance(other, basestring):
+ elif isinstance(other, str):
self.data += other
else:
self.data += str(other)
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py
index 2a9676f..37e19f2 100644
--- a/Lib/_abcoll.py
+++ b/Lib/_abcoll.py
@@ -490,7 +490,8 @@ class Sequence(metaclass=ABCMeta):
return sum(1 for v in self if v == value)
Sequence.register(tuple)
-Sequence.register(basestring)
+Sequence.register(str)
+Sequence.register(str8)
Sequence.register(memoryview)
diff --git a/Lib/binhex.py b/Lib/binhex.py
index e4d551f..61dda82 100644
--- a/Lib/binhex.py
+++ b/Lib/binhex.py
@@ -169,7 +169,7 @@ class _Rlecoderengine:
class BinHex:
def __init__(self, name_finfo_dlen_rlen, ofp):
name, finfo, dlen, rlen = name_finfo_dlen_rlen
- if isinstance(ofp, basestring):
+ if isinstance(ofp, str):
ofname = ofp
ofp = io.open(ofname, 'wb')
if os.name == 'mac':
@@ -371,7 +371,7 @@ class _Rledecoderengine:
class HexBin:
def __init__(self, ifp):
- if isinstance(ifp, basestring):
+ if isinstance(ifp, str):
ifp = io.open(ifp, 'rb')
#
# Find initial colon.
diff --git a/Lib/cProfile.py b/Lib/cProfile.py
index ae16277..5d04341 100755
--- a/Lib/cProfile.py
+++ b/Lib/cProfile.py
@@ -153,7 +153,7 @@ class Profile(_lsprof.Profiler):
# ____________________________________________________________
def label(code):
- if isinstance(code, basestring):
+ if isinstance(code, str):
return ('~', 0, code) # built-in functions ('~' sorts at the end)
else:
return (code.co_filename, code.co_firstlineno, code.co_name)
diff --git a/Lib/cmd.py b/Lib/cmd.py
index a2b2020..6f34e04 100644
--- a/Lib/cmd.py
+++ b/Lib/cmd.py
@@ -356,7 +356,7 @@ class Cmd:
return
nonstrings = [i for i in range(len(list))
- if not isinstance(list[i], basestring)]
+ if not isinstance(list[i], str)]
if nonstrings:
raise TypeError("list[i] not a string for i in %s"
% ", ".join(map(str, nonstrings)))
diff --git a/Lib/cookielib.py b/Lib/cookielib.py
index 3a716d2..4552412 100644
--- a/Lib/cookielib.py
+++ b/Lib/cookielib.py
@@ -367,7 +367,7 @@ def split_header_words(header_values):
[[('Basic', None), ('realm', '"foobar"')]]
"""
- assert not isinstance(header_values, basestring)
+ assert not isinstance(header_values, str)
result = []
for text in header_values:
orig_text = text
diff --git a/Lib/copy_reg.py b/Lib/copy_reg.py
index d693209..81a1e7f 100644
--- a/Lib/copy_reg.py
+++ b/Lib/copy_reg.py
@@ -114,7 +114,7 @@ def _slotnames(cls):
if "__slots__" in c.__dict__:
slots = c.__dict__['__slots__']
# if class has a single slot, it can be given as a string
- if isinstance(slots, basestring):
+ if isinstance(slots, str):
slots = (slots,)
for name in slots:
# special descriptors
diff --git a/Lib/decimal.py b/Lib/decimal.py
index ffe6e9e..cdb88bc 100644
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -588,7 +588,7 @@ class Decimal(object):
# From a string
# REs insist on real strings, so we can too.
- if isinstance(value, basestring):
+ if isinstance(value, str):
if _isinfinity(value):
self._exp = 'F'
self._int = (0,)
diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py
index c33e5ab..f4edb7c 100644
--- a/Lib/distutils/ccompiler.py
+++ b/Lib/distutils/ccompiler.py
@@ -154,7 +154,7 @@ class CCompiler:
self.set_executable(key, value)
def set_executable(self, key, value):
- if isinstance(value, basestring):
+ if isinstance(value, str):
setattr(self, key, split_quoted(value))
else:
setattr(self, key, value)
@@ -175,8 +175,8 @@ class CCompiler:
for defn in definitions:
if not (isinstance(defn, tuple) and
(len(defn) in (1, 2) and
- (isinstance (defn[1], basestring) or defn[1] is None)) and
- isinstance (defn[0], basestring)):
+ (isinstance (defn[1], str) or defn[1] is None)) and
+ isinstance (defn[0], str)):
raise TypeError(("invalid macro definition '%s': " % defn) + \
"must be tuple (string,), (string, string), or " + \
"(string, None)")
@@ -318,7 +318,7 @@ class CCompiler:
"""
if outdir is None:
outdir = self.output_dir
- elif not isinstance(outdir, basestring):
+ elif not isinstance(outdir, str):
raise TypeError("'output_dir' must be a string or None")
if macros is None:
@@ -415,7 +415,7 @@ class CCompiler:
"""
if output_dir is None:
output_dir = self.output_dir
- elif not isinstance(output_dir, basestring):
+ elif not isinstance(output_dir, str):
raise TypeError("'output_dir' must be a string or None")
if macros is None:
@@ -494,7 +494,7 @@ class CCompiler:
if output_dir is None:
output_dir = self.output_dir
- elif not isinstance(output_dir, basestring):
+ elif not isinstance(output_dir, str):
raise TypeError("'output_dir' must be a string or None")
return (objects, output_dir)
diff --git a/Lib/distutils/cmd.py b/Lib/distutils/cmd.py
index 66940f7..bd560a6 100644
--- a/Lib/distutils/cmd.py
+++ b/Lib/distutils/cmd.py
@@ -213,7 +213,7 @@ class Command:
if val is None:
setattr(self, option, default)
return default
- elif not isinstance(val, basestring):
+ elif not isinstance(val, str):
raise DistutilsOptionError("'%s' must be a %s (got `%s`)"
% (option, what, val))
return val
@@ -233,11 +233,11 @@ class Command:
val = getattr(self, option)
if val is None:
return
- elif isinstance(val, basestring):
+ elif isinstance(val, str):
setattr(self, option, re.split(r',\s*|\s+', val))
else:
if isinstance(val, list):
- ok = all(isinstance(v, basestring) for v in val)
+ ok = all(isinstance(v, str) for v in val)
else:
ok = False
if not ok:
@@ -390,7 +390,7 @@ class Command:
# Allow 'infiles' to be a single string
- if isinstance(infiles, basestring):
+ if isinstance(infiles, str):
infiles = (infiles,)
elif not isinstance(infiles, (list, tuple)):
raise TypeError(
diff --git a/Lib/distutils/command/build_clib.py b/Lib/distutils/command/build_clib.py
index 5f95207..34f4983 100644
--- a/Lib/distutils/command/build_clib.py
+++ b/Lib/distutils/command/build_clib.py
@@ -86,7 +86,7 @@ class build_clib(Command):
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
- if isinstance(self.include_dirs, basestring):
+ if isinstance(self.include_dirs, str):
self.include_dirs = self.include_dirs.split(os.pathsep)
# XXX same as for build_ext -- what about 'self.define' and
@@ -134,7 +134,7 @@ class build_clib(Command):
raise DistutilsSetupError(
"each element of 'libraries' must a 2-tuple")
- if isinstance(lib[0], basestring):
+ if isinstance(lib[0], str):
raise DistutilsSetupError(
"first element of each tuple in 'libraries' "
"must be a string (the library name)")
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index a439c49..ddf8f72 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -133,7 +133,7 @@ class build_ext(Command):
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
- if isinstance(self.include_dirs, basestring):
+ if isinstance(self.include_dirs, str):
self.include_dirs = self.include_dirs.split(os.pathsep)
# Put the Python "system" include dir at the end, so that
@@ -142,7 +142,7 @@ class build_ext(Command):
if plat_py_include != py_include:
self.include_dirs.append(plat_py_include)
- if isinstance(self.libraries, basestring):
+ if isinstance(self.libraries, str):
self.libraries = [self.libraries]
# Life is easier if we're not forever checking for None, so
@@ -151,12 +151,12 @@ class build_ext(Command):
self.libraries = []
if self.library_dirs is None:
self.library_dirs = []
- elif isinstance(self.library_dirs, basestring):
+ elif isinstance(self.library_dirs, str):
self.library_dirs = self.library_dirs.split(os.pathsep)
if self.rpath is None:
self.rpath = []
- elif isinstance(self.rpath, basestring):
+ elif isinstance(self.rpath, str):
self.rpath = self.rpath.split(os.pathsep)
# for extensions under windows use different directories
@@ -309,7 +309,7 @@ class build_ext(Command):
"each element of 'ext_modules' option must be an "
"Extension instance or 2-tuple")
- if not (isinstance(ext_name, basestring) and
+ if not (isinstance(ext_name, str) and
extension_name_re.match(ext_name)):
raise DistutilsSetupError(
"first element of each tuple in 'ext_modules' "
diff --git a/Lib/distutils/command/build_py.py b/Lib/distutils/command/build_py.py
index 454424f..63ced4b 100644
--- a/Lib/distutils/command/build_py.py
+++ b/Lib/distutils/command/build_py.py
@@ -325,7 +325,7 @@ class build_py (Command):
return outputs
def build_module(self, module, module_file, package):
- if isinstance(package, basestring):
+ if isinstance(package, str):
package = package.split('.')
elif not isinstance(package, (list, tuple)):
raise TypeError(
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index a601234..34f9188 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -69,17 +69,17 @@ class config(Command):
def finalize_options(self):
if self.include_dirs is None:
self.include_dirs = self.distribution.include_dirs or []
- elif isinstance(self.include_dirs, basestring):
+ elif isinstance(self.include_dirs, str):
self.include_dirs = self.include_dirs.split(os.pathsep)
if self.libraries is None:
self.libraries = []
- elif isinstance(self.libraries, basestring):
+ elif isinstance(self.libraries, str):
self.libraries = [self.libraries]
if self.library_dirs is None:
self.library_dirs = []
- elif isinstance(self.library_dirs, basestring):
+ elif isinstance(self.library_dirs, str):
self.library_dirs = self.library_dirs.split(os.pathsep)
def run(self):
@@ -204,7 +204,7 @@ class config(Command):
self._check_compiler()
(src, out) = self._preprocess(body, headers, include_dirs, lang)
- if isinstance(pattern, basestring):
+ if isinstance(pattern, str):
pattern = re.compile(pattern)
file = open(out)
diff --git a/Lib/distutils/command/install.py b/Lib/distutils/command/install.py
index f1ebcbf..b768663 100644
--- a/Lib/distutils/command/install.py
+++ b/Lib/distutils/command/install.py
@@ -449,7 +449,7 @@ class install (Command):
self.extra_path = self.distribution.extra_path
if self.extra_path is not None:
- if isinstance(self.extra_path, basestring):
+ if isinstance(self.extra_path, str):
self.extra_path = self.extra_path.split(',')
if len(self.extra_path) == 1:
diff --git a/Lib/distutils/command/install_data.py b/Lib/distutils/command/install_data.py
index 2fbac63..06a70b4 100644
--- a/Lib/distutils/command/install_data.py
+++ b/Lib/distutils/command/install_data.py
@@ -45,7 +45,7 @@ class install_data(Command):
def run(self):
self.mkpath(self.install_dir)
for f in self.data_files:
- if isinstance(f, basestring):
+ if isinstance(f, str):
# it's a simple file, so copy it
f = convert_path(f)
if self.warn_dir:
diff --git a/Lib/distutils/dir_util.py b/Lib/distutils/dir_util.py
index 30e352d..1f0d49c 100644
--- a/Lib/distutils/dir_util.py
+++ b/Lib/distutils/dir_util.py
@@ -28,7 +28,7 @@ def mkpath (name, mode=0o777, verbose=0, dry_run=0):
global _path_created
# Detect a common bug -- name is None
- if not isinstance(name, basestring):
+ if not isinstance(name, str):
raise DistutilsInternalError(
"mkpath: 'name' must be a string (got %r)" % (name,))
diff --git a/Lib/distutils/dist.py b/Lib/distutils/dist.py
index 631df48..ade2ab7 100644
--- a/Lib/distutils/dist.py
+++ b/Lib/distutils/dist.py
@@ -580,13 +580,13 @@ Common commands: (see '--help-commands' for more)
keywords = self.metadata.keywords
if keywords is not None:
- if isinstance(keywords, basestring):
+ if isinstance(keywords, str):
keywordlist = keywords.split(',')
self.metadata.keywords = [x.strip() for x in keywordlist]
platforms = self.metadata.platforms
if platforms is not None:
- if isinstance(platforms, basestring):
+ if isinstance(platforms, str):
platformlist = platforms.split(',')
self.metadata.platforms = [x.strip() for x in platformlist]
@@ -874,7 +874,7 @@ Common commands: (see '--help-commands' for more)
neg_opt = {}
try:
- is_string = isinstance(value, basestring)
+ is_string = isinstance(value, str)
if option in neg_opt and is_string:
setattr(command_obj, neg_opt[option], not strtobool(value))
elif option in bool_opts and is_string:
diff --git a/Lib/distutils/extension.py b/Lib/distutils/extension.py
index 7f5954e..b271816 100644
--- a/Lib/distutils/extension.py
+++ b/Lib/distutils/extension.py
@@ -102,9 +102,9 @@ class Extension:
language=None,
**kw # To catch unknown keywords
):
- assert isinstance(name, basestring), "'name' must be a string"
+ assert isinstance(name, str), "'name' must be a string"
assert (isinstance(sources, list) and
- all(isinstance(v, basestring) for v in sources)), \
+ all(isinstance(v, str) for v in sources)), \
"'sources' must be a list of strings"
self.name = name
diff --git a/Lib/distutils/fancy_getopt.py b/Lib/distutils/fancy_getopt.py
index b3231c3..72441fb 100644
--- a/Lib/distutils/fancy_getopt.py
+++ b/Lib/distutils/fancy_getopt.py
@@ -154,12 +154,12 @@ class FancyGetopt:
raise ValueError("invalid option tuple: %r" % (option,))
# Type- and value-check the option names
- if not isinstance(long, basestring) or len(long) < 2:
+ if not isinstance(long, str) or len(long) < 2:
raise DistutilsGetoptError(("invalid long option '%s': "
"must be a string of length >= 2") % long)
if (not ((short is None) or
- (isinstance(short, basestring) and len(short) == 1))):
+ (isinstance(short, str) and len(short) == 1))):
raise DistutilsGetoptError("invalid short option '%s': "
"must a single character or None" % short)
diff --git a/Lib/distutils/filelist.py b/Lib/distutils/filelist.py
index 8f80107..6506c30 100644
--- a/Lib/distutils/filelist.py
+++ b/Lib/distutils/filelist.py
@@ -301,7 +301,7 @@ def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
or just returned as-is (assumes it's a regex object).
"""
if is_regex:
- if isinstance(pattern, basestring):
+ if isinstance(pattern, str):
return re.compile(pattern)
else:
return pattern
diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
index 91d0dff..ee975e1 100644
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -211,7 +211,7 @@ class UnixCCompiler(CCompiler):
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
libraries)
- if not isinstance(output_dir, (basestring, type(None))):
+ if not isinstance(output_dir, (str, type(None))):
raise TypeError("'output_dir' must be a string or None")
if output_dir is not None:
output_filename = os.path.join(output_dir, output_filename)
diff --git a/Lib/doctest.py b/Lib/doctest.py
index 0b9be45..97bc053 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -443,7 +443,7 @@ class DocTest:
Create a new DocTest containing the given examples. The
DocTest's globals are initialized with a copy of `globs`.
"""
- assert not isinstance(examples, basestring), \
+ assert not isinstance(examples, str), \
"DocTest no longer accepts str; use DocTestParser instead"
self.examples = examples
self.docstring = docstring
@@ -875,13 +875,13 @@ class DocTestFinder:
# Look for tests in a module's __test__ dictionary.
if inspect.ismodule(obj) and self._recurse:
for valname, val in getattr(obj, '__test__', {}).items():
- if not isinstance(valname, basestring):
+ if not isinstance(valname, str):
raise ValueError("DocTestFinder.find: __test__ keys "
"must be strings: %r" %
(type(valname),))
if not (inspect.isfunction(val) or inspect.isclass(val) or
inspect.ismethod(val) or inspect.ismodule(val) or
- isinstance(val, basestring)):
+ isinstance(val, str)):
raise ValueError("DocTestFinder.find: __test__ values "
"must be strings, functions, methods, "
"classes, or modules: %r" %
@@ -914,7 +914,7 @@ class DocTestFinder:
"""
# Extract the object's docstring. If it doesn't have one,
# then return None (no test for this object).
- if isinstance(obj, basestring):
+ if isinstance(obj, str):
docstring = obj
else:
try:
@@ -922,7 +922,7 @@ class DocTestFinder:
docstring = ''
else:
docstring = obj.__doc__
- if not isinstance(docstring, basestring):
+ if not isinstance(docstring, str):
docstring = str(docstring)
except (TypeError, AttributeError):
docstring = ''
diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py
index 9ed8e4d..bff17ba 100644
--- a/Lib/email/feedparser.py
+++ b/Lib/email/feedparser.py
@@ -365,7 +365,7 @@ class FeedParser:
self._last.epilogue = epilogue[:-end]
else:
payload = self._last.get_payload()
- if isinstance(payload, basestring):
+ if isinstance(payload, str):
mo = NLCRE_eol.search(payload)
if mo:
payload = payload[:-len(mo.group(0))]
diff --git a/Lib/email/generator.py b/Lib/email/generator.py
index 2d6a191..d46549c 100644
--- a/Lib/email/generator.py
+++ b/Lib/email/generator.py
@@ -151,7 +151,7 @@ class Generator:
payload = msg.get_payload()
if payload is None:
return
- if not isinstance(payload, basestring):
+ if not isinstance(payload, str):
raise TypeError('string payload expected: %s' % type(payload))
if self._mangle_from_:
payload = fcre.sub('>From ', payload)
@@ -168,7 +168,7 @@ class Generator:
subparts = msg.get_payload()
if subparts is None:
subparts = []
- elif isinstance(subparts, basestring):
+ elif isinstance(subparts, str):
# e.g. a non-strict parse of a message with no starting boundary.
self._fp.write(subparts)
return
@@ -288,7 +288,7 @@ class DecodedGenerator(Generator):
for part in msg.walk():
maintype = part.get_content_maintype()
if maintype == 'text':
- print(part.get_payload(decode=True), file=self)
+ print(part.get_payload(decode=False), file=self)
elif maintype == 'multipart':
# Just skip this
pass
diff --git a/Lib/email/iterators.py b/Lib/email/iterators.py
index e4476e3..3adc4a0 100644
--- a/Lib/email/iterators.py
+++ b/Lib/email/iterators.py
@@ -39,7 +39,7 @@ def body_line_iterator(msg, decode=False):
"""
for subpart in msg.walk():
payload = subpart.get_payload(decode=decode)
- if isinstance(payload, basestring):
+ if isinstance(payload, str):
for line in StringIO(payload):
yield line
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index 5a423a1..0d7ffad 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -196,7 +196,7 @@ class FileInput:
def __init__(self, files=None, inplace=0, backup="", bufsize=0,
mode="r", openhook=None):
- if isinstance(files, basestring):
+ if isinstance(files, str):
files = (files,)
else:
if files is None:
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 97c2998..d0608d7 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -313,7 +313,7 @@ def getdoc(object):
doc = object.__doc__
except AttributeError:
return None
- if not isinstance(doc, basestring):
+ if not isinstance(doc, str):
return None
try:
lines = doc.expandtabs().split('\n')
diff --git a/Lib/io.py b/Lib/io.py
index ce7aee2..e7533b5 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -103,13 +103,13 @@ def open(file, mode="r", buffering=None, encoding=None, newline=None):
binary stream, a buffered binary stream, or a buffered text
stream, open for reading and/or writing.
"""
- if not isinstance(file, (basestring, int)):
+ if not isinstance(file, (str, int)):
raise TypeError("invalid file: %r" % file)
- if not isinstance(mode, basestring):
+ if not isinstance(mode, str):
raise TypeError("invalid mode: %r" % mode)
if buffering is not None and not isinstance(buffering, int):
raise TypeError("invalid buffering: %r" % buffering)
- if encoding is not None and not isinstance(encoding, basestring):
+ if encoding is not None and not isinstance(encoding, str):
raise TypeError("invalid encoding: %r" % encoding)
modes = set(mode)
if modes - set("arwb+tU") or len(mode) > len(modes):
@@ -1092,7 +1092,7 @@ class TextIOWrapper(TextIOBase):
def write(self, s: str):
if self.closed:
raise ValueError("write to closed file")
- if not isinstance(s, basestring):
+ if not isinstance(s, str):
raise TypeError("can't write %s to text stream" %
s.__class__.__name__)
haslf = "\n" in s
@@ -1394,7 +1394,7 @@ class StringIO(TextIOWrapper):
encoding=encoding,
newline=newline)
if initial_value:
- if not isinstance(initial_value, basestring):
+ if not isinstance(initial_value, str):
initial_value = str(initial_value)
self.write(initial_value)
self.seek(0)
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py
index f6c1ab4..f40a553 100644
--- a/Lib/lib-tk/Tkinter.py
+++ b/Lib/lib-tk/Tkinter.py
@@ -255,7 +255,7 @@ class StringVar(Variable):
def get(self):
"""Return value of variable as string."""
value = self._tk.globalgetvar(self._name)
- if isinstance(value, basestring):
+ if isinstance(value, str):
return value
return str(value)
diff --git a/Lib/locale.py b/Lib/locale.py
index b8bc567..3f30ca0 100644
--- a/Lib/locale.py
+++ b/Lib/locale.py
@@ -12,6 +12,7 @@
"""
import sys, encodings, encodings.aliases
+from __builtin__ import str as _builtin_str
# Try importing the _locale module.
#
@@ -472,7 +473,7 @@ def setlocale(category, locale=None):
category may be given as one of the LC_* values.
"""
- if locale and not isinstance(locale, basestring):
+ if locale and not isinstance(locale, _builtin_str):
# convert to string
locale = normalize(_build_localename(locale))
return _setlocale(category, locale)
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index e714760..2125a5e 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -281,7 +281,7 @@ class LogRecord:
msg = str(self.msg)
else:
msg = self.msg
- if not isinstance(msg, basestring):
+ if not isinstance(msg, str):
try:
msg = str(self.msg)
except UnicodeError:
diff --git a/Lib/msilib/__init__.py b/Lib/msilib/__init__.py
index 9595413..ae3823a 100644
--- a/Lib/msilib/__init__.py
+++ b/Lib/msilib/__init__.py
@@ -101,7 +101,7 @@ def add_data(db, table, values):
field = value[i]
if isinstance(field, int):
r.SetInteger(i+1,field)
- elif isinstance(field, basestring):
+ elif isinstance(field, str):
r.SetString(i+1,field)
elif field is None:
pass
diff --git a/Lib/optparse.py b/Lib/optparse.py
index b3de411..f702e1a 100644
--- a/Lib/optparse.py
+++ b/Lib/optparse.py
@@ -815,9 +815,6 @@ class Option:
SUPPRESS_HELP = "SUPPRESS"+"HELP"
SUPPRESS_USAGE = "SUPPRESS"+"USAGE"
-def isbasestring(x):
- return isinstance(x, basestring)
-
class Values:
def __init__(self, defaults=None):
@@ -994,7 +991,7 @@ class OptionContainer:
"""add_option(Option)
add_option(opt_str, ..., kwarg=val, ...)
"""
- if isbasestring(args[0]):
+ if isinstance(args[0], str):
option = self.option_class(*args, **kwargs)
elif len(args) == 1 and not kwargs:
option = args[0]
@@ -1294,7 +1291,7 @@ class OptionParser (OptionContainer):
defaults = self.defaults.copy()
for option in self._get_all_options():
default = defaults.get(option.dest)
- if isbasestring(default):
+ if isinstance(default, str):
opt_str = option.get_opt_string()
defaults[option.dest] = option.check_value(opt_str, default)
@@ -1305,7 +1302,7 @@ class OptionParser (OptionContainer):
def add_option_group(self, *args, **kwargs):
# XXX lots of overlap with OptionContainer.add_option()
- if isbasestring(args[0]):
+ if isinstance(args[0], str):
group = OptionGroup(self, *args, **kwargs)
elif len(args) == 1 and not kwargs:
group = args[0]
diff --git a/Lib/os.py b/Lib/os.py
index e8676d9..451f833 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -636,7 +636,7 @@ if not _exists("urandom"):
# Supply os.popen()
def popen(cmd, mode="r", buffering=None):
- if not isinstance(cmd, basestring):
+ if not isinstance(cmd, str):
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
if mode not in ("r", "w"):
raise ValueError("invalid mode %r" % mode)
diff --git a/Lib/pickle.py b/Lib/pickle.py
index 45e7a8e..18ad210 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -307,7 +307,7 @@ class Pickler:
(t.__name__, obj))
# Check for string returned by reduce(), meaning "save as global"
- if isinstance(rv, basestring):
+ if isinstance(rv, str):
self.save_global(obj, rv)
return
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 6ec3ac2..6b0fca7 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -701,7 +701,7 @@ class StackObject(object):
)
def __init__(self, name, obtype, doc):
- assert isinstance(name, basestring)
+ assert isinstance(name, str)
self.name = name
assert isinstance(obtype, type) or isinstance(obtype, tuple)
@@ -710,7 +710,7 @@ class StackObject(object):
assert isinstance(contained, type)
self.obtype = obtype
- assert isinstance(doc, basestring)
+ assert isinstance(doc, str)
self.doc = doc
def __repr__(self):
@@ -846,10 +846,10 @@ class OpcodeInfo(object):
def __init__(self, name, code, arg,
stack_before, stack_after, proto, doc):
- assert isinstance(name, basestring)
+ assert isinstance(name, str)
self.name = name
- assert isinstance(code, basestring)
+ assert isinstance(code, str)
assert len(code) == 1
self.code = code
@@ -869,7 +869,7 @@ class OpcodeInfo(object):
assert isinstance(proto, int) and 0 <= proto <= 2
self.proto = proto
- assert isinstance(doc, basestring)
+ assert isinstance(doc, str)
self.doc = doc
I = OpcodeInfo
diff --git a/Lib/pkgutil.py b/Lib/pkgutil.py
index 6e93a3e..9c1d07c 100644
--- a/Lib/pkgutil.py
+++ b/Lib/pkgutil.py
@@ -516,7 +516,7 @@ def extend_path(path, name):
path = path[:] # Start with a copy of the existing path
for dir in sys.path:
- if not isinstance(dir, basestring) or not os.path.isdir(dir):
+ if not isinstance(dir, str) or not os.path.isdir(dir):
continue
subdir = os.path.join(dir, pname)
# XXX This may still add duplicate entries to path on
diff --git a/Lib/pstats.py b/Lib/pstats.py
index cc0a7ac..4396433 100644
--- a/Lib/pstats.py
+++ b/Lib/pstats.py
@@ -116,7 +116,7 @@ class Stats:
def load_stats(self, arg):
if not arg: self.stats = {}
- elif isinstance(arg, basestring):
+ elif isinstance(arg, str):
f = open(arg, 'rb')
self.stats = marshal.load(f)
f.close()
diff --git a/Lib/shlex.py b/Lib/shlex.py
index 70feb89..55db23c 100644
--- a/Lib/shlex.py
+++ b/Lib/shlex.py
@@ -18,7 +18,7 @@ __all__ = ["shlex", "split"]
class shlex:
"A lexical analyzer class for simple shell-like syntaxes."
def __init__(self, instream=None, infile=None, posix=False):
- if isinstance(instream, basestring):
+ if isinstance(instream, str):
instream = StringIO(instream)
if instream is not None:
self.instream = instream
@@ -61,7 +61,7 @@ class shlex:
def push_source(self, newstream, newfile=None):
"Push an input source onto the lexer's input source stack."
- if isinstance(newstream, basestring):
+ if isinstance(newstream, str):
newstream = StringIO(newstream)
self.filestack.appendleft((self.infile, self.instream, self.lineno))
self.infile = newfile
@@ -247,7 +247,7 @@ class shlex:
if newfile[0] == '"':
newfile = newfile[1:-1]
# This implements cpp-like semantics for relative-path inclusion.
- if isinstance(self.infile, basestring) and not os.path.isabs(newfile):
+ if isinstance(self.infile, str) and not os.path.isabs(newfile):
newfile = os.path.join(os.path.dirname(self.infile), newfile)
return (newfile, open(newfile, "r"))
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 399444a..e10e327 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -668,7 +668,7 @@ class SMTP:
self.rset()
raise SMTPSenderRefused(code, resp, from_addr)
senderrs={}
- if isinstance(to_addrs, basestring):
+ if isinstance(to_addrs, str):
to_addrs = [to_addrs]
for each in to_addrs:
(code,resp)=self.rcpt(each, rcpt_options)
diff --git a/Lib/sre_compile.py b/Lib/sre_compile.py
index 505af92..f9f0736 100644
--- a/Lib/sre_compile.py
+++ b/Lib/sre_compile.py
@@ -472,7 +472,7 @@ def _compile_info(code, pattern, flags):
code[skip] = len(code) - skip
def isstring(obj):
- return isinstance(obj, basestring)
+ return isinstance(obj, str)
def _code(p, flags):
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index a34eb29..6b9bb6b 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -698,7 +698,7 @@ class Popen(object):
errread, errwrite):
"""Execute program (MS Windows version)"""
- if not isinstance(args, basestring):
+ if not isinstance(args, str):
args = list2cmdline(args)
# Process startup details
@@ -913,7 +913,7 @@ class Popen(object):
errread, errwrite):
"""Execute program (POSIX version)"""
- if isinstance(args, basestring):
+ if isinstance(args, str):
args = [args]
else:
args = list(args)
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index a840a1a..188b61e 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2041,7 +2041,7 @@ class TarFile(object):
"""
self._check("r")
- if isinstance(member, basestring):
+ if isinstance(member, str):
tarinfo = self.getmember(member)
else:
tarinfo = member
@@ -2077,7 +2077,7 @@ class TarFile(object):
"""
self._check("r")
- if isinstance(member, basestring):
+ if isinstance(member, str):
tarinfo = self.getmember(member)
else:
tarinfo = member
diff --git a/Lib/test/test___future__.py b/Lib/test/test___future__.py
index 50a2c74..9504155 100644
--- a/Lib/test/test___future__.py
+++ b/Lib/test/test___future__.py
@@ -39,7 +39,7 @@ class FutureTest(unittest.TestCase):
a(isinstance(major, int), "%s major isn't int" % name)
a(isinstance(minor, int), "%s minor isn't int" % name)
a(isinstance(micro, int), "%s micro isn't int" % name)
- a(isinstance(level, basestring),
+ a(isinstance(level, str),
"%s level isn't string" % name)
a(level in GOOD_SERIALS,
"%s level string has unknown value" % name)
diff --git a/Lib/test/test_abc.py b/Lib/test/test_abc.py
index 008d839..e6c8415 100644
--- a/Lib/test/test_abc.py
+++ b/Lib/test/test_abc.py
@@ -81,9 +81,11 @@ class TestABC(unittest.TestCase):
self.assertEqual(issubclass(int, A), True)
class B(A):
pass
- B.register(basestring)
+ B.register(str)
+ class C(str): pass
self.assertEqual(isinstance("", A), True)
self.assertEqual(issubclass(str, A), True)
+ self.assertEqual(issubclass(C, A), True)
def test_registration_edge_cases(self):
class A(metaclass=abc.ABCMeta):
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py
index 6299123..4883ed5 100644
--- a/Lib/test/test_ast.py
+++ b/Lib/test/test_ast.py
@@ -2,7 +2,7 @@ import sys, itertools
import _ast
def to_tuple(t):
- if t is None or isinstance(t, (basestring, int, int, complex)):
+ if t is None or isinstance(t, (str, int, complex)):
return t
elif isinstance(t, list):
return [to_tuple(e) for e in t]
diff --git a/Lib/test/test_codeccallbacks.py b/Lib/test/test_codeccallbacks.py
index 6d7e98e..eedd48a 100644
--- a/Lib/test/test_codeccallbacks.py
+++ b/Lib/test/test_codeccallbacks.py
@@ -140,17 +140,17 @@ class CodecCallbackTest(unittest.TestCase):
sin += chr(sys.maxunicode)
sout = b"a\\xac\\u1234\\u20ac\\u8000"
if sys.maxunicode > 0xffff:
- sout += bytes("\\U%08x" % sys.maxunicode)
+ sout += bytes("\\U%08x" % sys.maxunicode, "ascii")
self.assertEqual(sin.encode("ascii", "backslashreplace"), sout)
sout = b"a\xac\\u1234\\u20ac\\u8000"
if sys.maxunicode > 0xffff:
- sout += bytes("\\U%08x" % sys.maxunicode)
+ sout += bytes("\\U%08x" % sys.maxunicode, "ascii")
self.assertEqual(sin.encode("latin-1", "backslashreplace"), sout)
sout = b"a\xac\\u1234\xa4\\u8000"
if sys.maxunicode > 0xffff:
- sout += bytes("\\U%08x" % sys.maxunicode)
+ sout += bytes("\\U%08x" % sys.maxunicode, "ascii")
self.assertEqual(sin.encode("iso-8859-15", "backslashreplace"), sout)
def test_decoderelaxedutf8(self):
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 2d531d2..22db2ca 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -803,8 +803,9 @@ class UnicodeInternalTest(unittest.TestCase):
codecs.register_error("UnicodeInternalTest", codecs.ignore_errors)
decoder = codecs.getdecoder("unicode_internal")
ab = "ab".encode("unicode_internal")
- ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:])),
- "UnicodeInternalTest")
+ ignored = decoder(bytes("%s\x22\x22\x22\x22%s" % (ab[:4], ab[4:]),
+ "ascii"),
+ "UnicodeInternalTest")
self.assertEquals(("ab", 12), ignored)
# From http://www.gnu.org/software/libidn/draft-josefsson-idn-test-vectors.html
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 24266ed..568e682 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -235,7 +235,7 @@ class TestCollectionABCs(unittest.TestCase):
for sample in [tuple, list, bytes, str]:
self.failUnless(isinstance(sample(), Sequence))
self.failUnless(issubclass(sample, Sequence))
- self.failUnless(issubclass(basestring, Sequence))
+ self.failUnless(issubclass(str, Sequence))
def test_MutableSequence(self):
for sample in [tuple, str]:
@@ -244,7 +244,7 @@ class TestCollectionABCs(unittest.TestCase):
for sample in [list, bytes]:
self.failUnless(isinstance(sample(), MutableSequence))
self.failUnless(issubclass(sample, MutableSequence))
- self.failIf(issubclass(basestring, MutableSequence))
+ self.failIf(issubclass(str, MutableSequence))
def test_main(verbose=None):
diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py
index 978dee9..24b3f00 100755
--- a/Lib/test/test_grp.py
+++ b/Lib/test/test_grp.py
@@ -11,9 +11,9 @@ class GroupDatabaseTestCase(unittest.TestCase):
# attributes promised by the docs
self.assertEqual(len(value), 4)
self.assertEqual(value[0], value.gr_name)
- self.assert_(isinstance(value.gr_name, basestring))
+ self.assert_(isinstance(value.gr_name, str))
self.assertEqual(value[1], value.gr_passwd)
- self.assert_(isinstance(value.gr_passwd, basestring))
+ self.assert_(isinstance(value.gr_passwd, str))
self.assertEqual(value[2], value.gr_gid)
self.assert_(isinstance(value.gr_gid, int))
self.assertEqual(value[3], value.gr_mem)
diff --git a/Lib/test/test_isinstance.py b/Lib/test/test_isinstance.py
index c10fd32..1e29f4c 100644
--- a/Lib/test/test_isinstance.py
+++ b/Lib/test/test_isinstance.py
@@ -242,7 +242,7 @@ class TestIsInstanceIsSubclass(unittest.TestCase):
self.assertEqual(True, issubclass(NewSuper, (NewChild, (NewSuper,))))
self.assertEqual(True, issubclass(int, (int, (float, int))))
- self.assertEqual(True, issubclass(str, (str, (Child, NewChild, basestring))))
+ self.assertEqual(True, issubclass(str, (str, (Child, NewChild, str))))
def test_subclass_recursion_limit(self):
# make sure that issubclass raises RuntimeError before the C stack is
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 3eb981d..8c0d5ff 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -335,15 +335,15 @@ class PosixPathTest(unittest.TestCase):
except ImportError:
pass
else:
- self.assert_(isinstance(posixpath.expanduser("~/"), basestring))
+ self.assert_(isinstance(posixpath.expanduser("~/"), str))
# if home directory == root directory, this test makes no sense
if posixpath.expanduser("~") != '/':
self.assertEqual(
posixpath.expanduser("~") + "/",
posixpath.expanduser("~/")
)
- self.assert_(isinstance(posixpath.expanduser("~root/"), basestring))
- self.assert_(isinstance(posixpath.expanduser("~foo/"), basestring))
+ self.assert_(isinstance(posixpath.expanduser("~root/"), str))
+ self.assert_(isinstance(posixpath.expanduser("~foo/"), str))
self.assertRaises(TypeError, posixpath.expanduser)
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index 7abf905..358b8b3 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -13,19 +13,19 @@ class PwdTest(unittest.TestCase):
for e in entries:
self.assertEqual(len(e), 7)
self.assertEqual(e[0], e.pw_name)
- self.assert_(isinstance(e.pw_name, basestring))
+ self.assert_(isinstance(e.pw_name, str))
self.assertEqual(e[1], e.pw_passwd)
- self.assert_(isinstance(e.pw_passwd, basestring))
+ self.assert_(isinstance(e.pw_passwd, str))
self.assertEqual(e[2], e.pw_uid)
self.assert_(isinstance(e.pw_uid, int))
self.assertEqual(e[3], e.pw_gid)
self.assert_(isinstance(e.pw_gid, int))
self.assertEqual(e[4], e.pw_gecos)
- self.assert_(isinstance(e.pw_gecos, basestring))
+ self.assert_(isinstance(e.pw_gecos, str))
self.assertEqual(e[5], e.pw_dir)
- self.assert_(isinstance(e.pw_dir, basestring))
+ self.assert_(isinstance(e.pw_dir, str))
self.assertEqual(e[6], e.pw_shell)
- self.assert_(isinstance(e.pw_shell, basestring))
+ self.assert_(isinstance(e.pw_shell, str))
# The following won't work, because of duplicate entries
# for one uid
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index 1ede133..f935e1d 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -591,9 +591,10 @@ class ReTests(unittest.TestCase):
self.assertEqual([item.group(0) for item in iter],
[":", "::", ":::"])
- def test_bug_926075(self):
- self.assert_(re.compile('bug_926075') is not
- re.compile(str8('bug_926075')))
+ # XXX This needs to be restored for str vs. bytes.
+## def test_bug_926075(self):
+## self.assert_(re.compile('bug_926075') is not
+## re.compile(str8('bug_926075')))
def test_bug_931848(self):
pattern = eval('"[\u002E\u3002\uFF0E\uFF61]"')
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index 5b2176e..fb634f6 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -529,7 +529,7 @@ def run_unittest(*classes):
valid_types = (unittest.TestSuite, unittest.TestCase)
suite = unittest.TestSuite()
for cls in classes:
- if isinstance(cls, basestring):
+ if isinstance(cls, str):
if cls in sys.modules:
suite.addTest(unittest.findTestCases(sys.modules[cls]))
else:
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index e737047..ddf1876 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -126,7 +126,7 @@ class SysModuleTest(unittest.TestCase):
def test_getdefaultencoding(self):
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
# can't check more than the type, as the user might have changed it
- self.assert_(isinstance(sys.getdefaultencoding(), basestring))
+ self.assert_(isinstance(sys.getdefaultencoding(), str))
# testing sys.settrace() is done in test_trace.py
# testing sys.setprofile() is done in test_profile.py
@@ -275,15 +275,15 @@ class SysModuleTest(unittest.TestCase):
self.assert_(isinstance(sys.argv, list))
self.assert_(sys.byteorder in ("little", "big"))
self.assert_(isinstance(sys.builtin_module_names, tuple))
- self.assert_(isinstance(sys.copyright, basestring))
- self.assert_(isinstance(sys.exec_prefix, basestring))
- self.assert_(isinstance(sys.executable, basestring))
+ self.assert_(isinstance(sys.copyright, str))
+ self.assert_(isinstance(sys.exec_prefix, str))
+ self.assert_(isinstance(sys.executable, str))
self.assert_(isinstance(sys.hexversion, int))
self.assert_(isinstance(sys.maxint, int))
self.assert_(isinstance(sys.maxunicode, int))
- self.assert_(isinstance(sys.platform, basestring))
- self.assert_(isinstance(sys.prefix, basestring))
- self.assert_(isinstance(sys.version, basestring))
+ self.assert_(isinstance(sys.platform, str))
+ self.assert_(isinstance(sys.prefix, str))
+ self.assert_(isinstance(sys.version, str))
vi = sys.version_info
self.assert_(isinstance(vi, tuple))
self.assertEqual(len(vi), 5)
diff --git a/Lib/test/test_tempfile.py b/Lib/test/test_tempfile.py
index 3e4f803..8d91927 100644
--- a/Lib/test/test_tempfile.py
+++ b/Lib/test/test_tempfile.py
@@ -143,7 +143,7 @@ class test__candidate_tempdir_list(TC):
self.failIf(len(cand) == 0)
for c in cand:
- self.assert_(isinstance(c, basestring),
+ self.assert_(isinstance(c, str),
"%s is not a string" % c)
def test_wanted_dirs(self):
@@ -328,7 +328,7 @@ class test_gettempprefix(TC):
# gettempprefix returns a nonempty prefix string
p = tempfile.gettempprefix()
- self.assert_(isinstance(p, basestring))
+ self.assert_(isinstance(p, str))
self.assert_(len(p) > 0)
def test_usable_template(self):
@@ -463,7 +463,7 @@ class test_mkdtemp(TC):
extant[i] = self.do_create(pre="aa")
finally:
for i in extant:
- if(isinstance(i, basestring)):
+ if(isinstance(i, str)):
os.rmdir(i)
def test_choose_directory(self):
diff --git a/Lib/test/test_textwrap.py b/Lib/test/test_textwrap.py
index 89316bc..b226c71 100644
--- a/Lib/test/test_textwrap.py
+++ b/Lib/test/test_textwrap.py
@@ -23,7 +23,7 @@ class BaseTestCase(unittest.TestCase):
for i in range(len(textin)):
result.append(" %d: %r" % (i, textin[i]))
result = '\n'.join(result)
- elif isinstance(textin, basestring):
+ elif isinstance(textin, str):
result = " %s\n" % repr(textin)
return result
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py
index 9b43f45..eac8074 100644
--- a/Lib/test/test_unittest.py
+++ b/Lib/test/test_unittest.py
@@ -1718,7 +1718,7 @@ class Test_FunctionTestCase(TestCase):
def test_id(self):
test = unittest.FunctionTestCase(lambda: None)
- self.failUnless(isinstance(test.id(), basestring))
+ self.failUnless(isinstance(test.id(), str))
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
@@ -2239,7 +2239,7 @@ class Test_TestCase(TestCase, TestEquality, TestHashing):
def runTest(self):
pass
- self.failUnless(isinstance(Foo().id(), basestring))
+ self.failUnless(isinstance(Foo().id(), str))
# "Returns a one-line description of the test, or None if no description
# has been provided. The default implementation of this method returns
diff --git a/Lib/timeit.py b/Lib/timeit.py
index 1d2bf08..5ce9b4a 100644
--- a/Lib/timeit.py
+++ b/Lib/timeit.py
@@ -121,9 +121,9 @@ class Timer:
"""Constructor. See class doc string."""
self.timer = timer
ns = {}
- if isinstance(stmt, basestring):
+ if isinstance(stmt, str):
stmt = reindent(stmt, 8)
- if isinstance(setup, basestring):
+ if isinstance(setup, str):
setup = reindent(setup, 4)
src = template % {'stmt': stmt, 'setup': setup}
elif hasattr(setup, '__call__'):
@@ -137,7 +137,7 @@ class Timer:
self.inner = ns["inner"]
elif hasattr(stmt, '__call__'):
self.src = None
- if isinstance(setup, basestring):
+ if isinstance(setup, str):
_setup = setup
def setup():
exec(_setup, globals(), ns)
diff --git a/Lib/unittest.py b/Lib/unittest.py
index bd72d90..c590558 100644
--- a/Lib/unittest.py
+++ b/Lib/unittest.py
@@ -418,7 +418,7 @@ class TestSuite:
self._tests.append(test)
def addTests(self, tests):
- if isinstance(tests, basestring):
+ if isinstance(tests, str):
raise TypeError("tests must be an iterable of tests, not a string")
for test in tests:
self.addTest(test)
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 2aa90d7..e990128 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -359,7 +359,7 @@ class OpenerDirector:
def open(self, fullurl, data=None, timeout=None):
# accept a URL or a Request object
- if isinstance(fullurl, basestring):
+ if isinstance(fullurl, str):
req = Request(fullurl, data)
else:
req = fullurl
@@ -702,7 +702,7 @@ class HTTPPasswordMgr:
def add_password(self, realm, uri, user, passwd):
# uri could be a single URI or a sequence
- if isinstance(uri, basestring):
+ if isinstance(uri, str):
uri = [uri]
if not realm in self.passwd:
self.passwd[realm] = {}
diff --git a/Lib/uu.py b/Lib/uu.py
index 18a9f79..da096ea 100755
--- a/Lib/uu.py
+++ b/Lib/uu.py
@@ -46,7 +46,7 @@ def encode(in_file, out_file, name=None, mode=None):
#
if in_file == '-':
in_file = sys.stdin.buffer
- elif isinstance(in_file, basestring):
+ elif isinstance(in_file, str):
if name is None:
name = os.path.basename(in_file)
if mode is None:
@@ -60,7 +60,7 @@ def encode(in_file, out_file, name=None, mode=None):
#
if out_file == '-':
out_file = sys.stdout.buffer
- elif isinstance(out_file, basestring):
+ elif isinstance(out_file, str):
out_file = open(out_file, 'wb')
#
# Set defaults for name and mode
@@ -87,7 +87,7 @@ def decode(in_file, out_file=None, mode=None, quiet=0):
#
if in_file == '-':
in_file = sys.stdin.buffer
- elif isinstance(in_file, basestring):
+ elif isinstance(in_file, str):
in_file = open(in_file, 'rb')
#
# Read until a begin is encountered or we've exhausted the file
@@ -118,7 +118,7 @@ def decode(in_file, out_file=None, mode=None, quiet=0):
opened = False
if out_file == '-':
out_file = sys.stdout.buffer
- elif isinstance(out_file, basestring):
+ elif isinstance(out_file, str):
fp = open(out_file, 'wb')
try:
os.path.chmod(out_file, mode)
@@ -169,7 +169,7 @@ def test():
if options.decode:
if options.text:
- if isinstance(output, basestring):
+ if isinstance(output, str):
output = open(output, 'wb')
else:
print(sys.argv[0], ': cannot do -t to stdout')
@@ -177,7 +177,7 @@ def test():
decode(input, output)
else:
if options.text:
- if isinstance(input, basestring):
+ if isinstance(input, str):
input = open(input, 'rb')
else:
print(sys.argv[0], ': cannot do -t from stdin')
diff --git a/Lib/warnings.py b/Lib/warnings.py
index ae17c7b..40079ba 100644
--- a/Lib/warnings.py
+++ b/Lib/warnings.py
@@ -150,10 +150,10 @@ def filterwarnings(action, message="", category=Warning, module="", lineno=0,
import re
assert action in ("error", "ignore", "always", "default", "module",
"once"), "invalid action: %r" % (action,)
- assert isinstance(message, basestring), "message must be a string"
+ assert isinstance(message, str), "message must be a string"
assert isinstance(category, type), "category must be a class"
assert issubclass(category, Warning), "category must be a Warning subclass"
- assert isinstance(module, basestring), "module must be a string"
+ assert isinstance(module, str), "module must be a string"
assert isinstance(lineno, int) and lineno >= 0, \
"lineno must be an int >= 0"
item = (action, re.compile(message, re.I), category,
diff --git a/Lib/wave.py b/Lib/wave.py
index 4fc1bf1..eda3697 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -155,7 +155,7 @@ class Wave_read:
def __init__(self, f):
self._i_opened_the_file = None
- if isinstance(f, basestring):
+ if isinstance(f, str):
f = __builtin__.open(f, 'rb')
self._i_opened_the_file = f
# else, assume it is an open file object already
@@ -299,7 +299,7 @@ class Wave_write:
def __init__(self, f):
self._i_opened_the_file = None
- if isinstance(f, basestring):
+ if isinstance(f, str):
f = __builtin__.open(f, 'wb')
self._i_opened_the_file = f
try:
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index d15f59c..a028df0 100644
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -159,7 +159,7 @@ class GenericBrowser(BaseBrowser):
and without remote functionality."""
def __init__(self, name):
- if isinstance(name, basestring):
+ if isinstance(name, str):
self.name = name
self.args = ["%s"]
else:
diff --git a/Lib/xml/dom/pulldom.py b/Lib/xml/dom/pulldom.py
index c15618f..81a36b0 100644
--- a/Lib/xml/dom/pulldom.py
+++ b/Lib/xml/dom/pulldom.py
@@ -325,7 +325,7 @@ default_bufsize = (2 ** 14) - 20
def parse(stream_or_string, parser=None, bufsize=None):
if bufsize is None:
bufsize = default_bufsize
- if isinstance(stream_or_string, basestring):
+ if isinstance(stream_or_string, str):
stream = open(stream_or_string)
else:
stream = stream_or_string
diff --git a/Lib/xml/sax/saxutils.py b/Lib/xml/sax/saxutils.py
index a4bcb08..a569c1d 100644
--- a/Lib/xml/sax/saxutils.py
+++ b/Lib/xml/sax/saxutils.py
@@ -272,7 +272,7 @@ def prepare_input_source(source, base = ""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
- if isinstance(source, basestring):
+ if isinstance(source, str):
source = xmlreader.InputSource(source)
elif hasattr(source, "read"):
f = source
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index e08d405..efb0a7b 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -294,7 +294,7 @@ class DateTime:
"""
def __init__(self, value=0):
- if not isinstance(value, basestring):
+ if not isinstance(value, str):
if datetime and isinstance(value, datetime.datetime):
self.value = value.strftime("%Y%m%dT%H:%M:%S")
return
@@ -653,7 +653,7 @@ class Marshaller:
write("<value><struct>\n")
for k, v in value.items():
write("<member>\n")
- if not isinstance(k, basestring):
+ if not isinstance(k, str):
raise TypeError("dictionary key must be string")
write("<name>%s</name>\n" % escape(k))
dump(v, write)
@@ -1031,7 +1031,7 @@ def dumps(params, methodname=None, methodresponse=None, encoding=None,
# standard XML-RPC wrappings
if methodname:
# a method call
- if not isinstance(methodname, basestring):
+ if not isinstance(methodname, str):
methodname = methodname.encode(encoding)
data = (
xmlheader,
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index c72c315..088f4a0 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -596,7 +596,7 @@ class ZipFile:
self.pwd = None
# Check if we were passed a file-like object
- if isinstance(file, basestring):
+ if isinstance(file, str):
# No, it's a filename
self._filePassed = 0
self.filename = file
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 0df85b6..2ebbf38 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -62,7 +62,7 @@ module instead.
/* end 2.2 compatibility macros */
#define IS_BASESTRING(o) \
- PyObject_TypeCheck(o, &PyBaseString_Type)
+ PyUnicode_Check(o)
static PyObject *error_obj; /* CSV exception */
static PyObject *dialects; /* Dialect registry */
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 83e3cfa..699ae27 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -3073,14 +3073,6 @@ str_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
static PyObject *
-basestring_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyErr_SetString(PyExc_TypeError,
- "The basestring type cannot be instantiated");
- return NULL;
-}
-
-static PyObject *
string_mod(PyObject *v, PyObject *w)
{
if (!PyString_Check(v)) {
@@ -3090,9 +3082,6 @@ string_mod(PyObject *v, PyObject *w)
return PyString_Format(v, w);
}
-PyDoc_STRVAR(basestring_doc,
-"Type basestring cannot be instantiated; it is the base for str8 and str.");
-
static PyNumberMethods string_as_number = {
0, /*nb_add*/
0, /*nb_subtract*/
@@ -3100,49 +3089,6 @@ static PyNumberMethods string_as_number = {
string_mod, /*nb_remainder*/
};
-
-PyTypeObject PyBaseString_Type = {
- PyVarObject_HEAD_INIT(&PyType_Type, 0)
- "basestring",
- 0,
- 0,
- 0, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- basestring_doc, /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- &PyBaseObject_Type, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- 0, /* tp_init */
- 0, /* tp_alloc */
- basestring_new, /* tp_new */
- 0, /* tp_free */
-};
-
PyDoc_STRVAR(string_doc,
"str(object) -> string\n\
\n\
@@ -3183,7 +3129,7 @@ PyTypeObject PyString_Type = {
string_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
- &PyBaseString_Type, /* tp_base */
+ &PyBaseObject_Type, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
@@ -3615,7 +3561,7 @@ PyString_Format(PyObject *format, PyObject *args)
argidx = -2;
}
if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
- !PyObject_TypeCheck(args, &PyBaseString_Type))
+ !PyString_Check(args) && !PyUnicode_Check(args))
dict = args;
while (--fmtcnt >= 0) {
if (*fmt != '%') {
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b2c24d7..fed2ff5 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8441,7 +8441,7 @@ PyObject *PyUnicode_Format(PyObject *format,
argidx = -2;
}
if (Py_Type(args)->tp_as_mapping && !PyTuple_Check(args) &&
- !PyObject_TypeCheck(args, &PyBaseString_Type))
+ !PyString_Check(args) && !PyUnicode_Check(args))
dict = args;
while (--fmtcnt >= 0) {
@@ -8935,7 +8935,7 @@ PyTypeObject PyUnicode_Type = {
unicode_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
- &PyBaseString_Type, /* tp_base */
+ &PyBaseObject_Type, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 338c424..70f1170 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1595,12 +1595,19 @@ builtin_sum(PyObject *self, PyObject *args)
}
} else {
/* reject string values for 'start' parameter */
- if (PyObject_TypeCheck(result, &PyBaseString_Type)) {
+ if (PyUnicode_Check(result)) {
PyErr_SetString(PyExc_TypeError,
"sum() can't sum strings [use ''.join(seq) instead]");
Py_DECREF(iter);
return NULL;
}
+ if (PyBytes_Check(result)) {
+ PyErr_SetString(PyExc_TypeError,
+ "sum() can't sum bytes [use b''.join(seq) instead]");
+ Py_DECREF(iter);
+ return NULL;
+ }
+
Py_INCREF(result);
}
@@ -1788,7 +1795,6 @@ _PyBuiltin_Init(void)
SETBUILTIN("NotImplemented", Py_NotImplemented);
SETBUILTIN("False", Py_False);
SETBUILTIN("True", Py_True);
- SETBUILTIN("basestring", &PyBaseString_Type);
SETBUILTIN("bool", &PyBool_Type);
SETBUILTIN("memoryview", &PyMemoryView_Type);
SETBUILTIN("bytes", &PyBytes_Type);