Skip to content

Commit

Permalink
Patch# 1258 by Christian Heimes: kill basestring.
Browse files Browse the repository at this point in the history
I like this because it makes the code shorter! :-)
  • Loading branch information
gvanrossum committed Oct 16, 2007
1 parent 60d241f commit 3172c5d
Show file tree
Hide file tree
Showing 77 changed files with 171 additions and 217 deletions.
1 change: 0 additions & 1 deletion Include/stringobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ typedef struct {
*/
} PyStringObject;

PyAPI_DATA(PyTypeObject) PyBaseString_Type;
PyAPI_DATA(PyTypeObject) PyString_Type;

#define PyString_Check(op) \
Expand Down
4 changes: 2 additions & 2 deletions Lib/ConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def read(self, filenames):
Return list of successfully read files.
"""
if isinstance(filenames, basestring):
if isinstance(filenames, str):
filenames = [filenames]
read_ok = []
for filename in filenames:
Expand Down Expand Up @@ -652,7 +652,7 @@ def _interpolate_some(self, option, accum, rest, section, map, depth):

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
Expand Down
10 changes: 5 additions & 5 deletions Lib/UserString.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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[:]
Expand Down Expand Up @@ -66,12 +66,12 @@ def __getitem__(self, index): return self.__class__(self.data[index])
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)
Expand Down Expand Up @@ -184,7 +184,7 @@ def __setitem__(self, index, sub):
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:
Expand Down Expand Up @@ -221,7 +221,7 @@ def immutable(self):
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)
Expand Down
3 changes: 2 additions & 1 deletion Lib/_abcoll.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@ def count(self, value):
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)


Expand Down
4 changes: 2 additions & 2 deletions Lib/binhex.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def close(self):
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':
Expand Down Expand Up @@ -371,7 +371,7 @@ def close(self):

class HexBin:
def __init__(self, ifp):
if isinstance(ifp, basestring):
if isinstance(ifp, str):
ifp = io.open(ifp, 'rb')
#
# Find initial colon.
Expand Down
2 changes: 1 addition & 1 deletion Lib/cProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def runcall(self, func, *args, **kw):
# ____________________________________________________________

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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def columnize(self, list, displaywidth=80):
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)))
Expand Down
2 changes: 1 addition & 1 deletion Lib/cookielib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Lib/copy_reg.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class found there. (This assumes classes don't modify their
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
Expand Down
2 changes: 1 addition & 1 deletion Lib/decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ def __new__(cls, value="0", context=None):

# 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,)
Expand Down
12 changes: 6 additions & 6 deletions Lib/distutils/ccompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class (via the 'executables' class attribute), but most will have:
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)
Expand All @@ -175,8 +175,8 @@ def _check_macro_definitions(self, definitions):
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)")
Expand Down Expand Up @@ -318,7 +318,7 @@ def _setup_compile(self, outdir, macros, incdirs, sources, depends,
"""
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:
Expand Down Expand Up @@ -415,7 +415,7 @@ def _fix_compile_args(self, output_dir, macros, include_dirs):
"""
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:
Expand Down Expand Up @@ -494,7 +494,7 @@ def _fix_object_args(self, objects, output_dir):

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)
Expand Down
8 changes: 4 additions & 4 deletions Lib/distutils/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _ensure_stringlike(self, option, what, default=None):
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
Expand All @@ -233,11 +233,11 @@ def ensure_string_list(self, option):
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:
Expand Down Expand Up @@ -390,7 +390,7 @@ def make_file(self, infiles, outfile, func, args,


# 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(
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/command/build_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def finalize_options(self):

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
Expand Down Expand Up @@ -134,7 +134,7 @@ def check_library_list(self, libraries):
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)")
Expand Down
10 changes: 5 additions & 5 deletions Lib/distutils/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def finalize_options(self):
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
Expand All @@ -142,7 +142,7 @@ def finalize_options(self):
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
Expand All @@ -151,12 +151,12 @@ def finalize_options(self):
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
Expand Down Expand Up @@ -309,7 +309,7 @@ def check_extensions_list(self, extensions):
"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' "
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/command/build_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def get_outputs(self, include_bytecode=1):
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(
Expand Down
8 changes: 4 additions & 4 deletions Lib/distutils/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ def initialize_options(self):
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):
Expand Down Expand Up @@ -204,7 +204,7 @@ def search_cpp(self, pattern, body=None, headers=None,
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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def handle_extra_path(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/command/install_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def finalize_options(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion Lib/distutils/dir_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,))

Expand Down
6 changes: 3 additions & 3 deletions Lib/distutils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,13 +580,13 @@ def finalize_options (self):

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]

Expand Down Expand Up @@ -874,7 +874,7 @@ def _set_command_options (self, command_obj, option_dict=None):
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:
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def __init__(self, name, sources,
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
Expand Down
4 changes: 2 additions & 2 deletions Lib/distutils/fancy_getopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@ def _grok_option_table(self):
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)

Expand Down
Loading

0 comments on commit 3172c5d

Please sign in to comment.