Skip to content

Commit 3172c5d

Browse files
committed
Patch# 1258 by Christian Heimes: kill basestring.
I like this because it makes the code shorter! :-)
1 parent 60d241f commit 3172c5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+171
-217
lines changed

Include/stringobject.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ typedef struct {
4848
*/
4949
} PyStringObject;
5050

51-
PyAPI_DATA(PyTypeObject) PyBaseString_Type;
5251
PyAPI_DATA(PyTypeObject) PyString_Type;
5352

5453
#define PyString_Check(op) \

Lib/ConfigParser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def read(self, filenames):
271271
272272
Return list of successfully read files.
273273
"""
274-
if isinstance(filenames, basestring):
274+
if isinstance(filenames, str):
275275
filenames = [filenames]
276276
read_ok = []
277277
for filename in filenames:
@@ -652,7 +652,7 @@ def _interpolate_some(self, option, accum, rest, section, map, depth):
652652

653653
def set(self, section, option, value):
654654
"""Set an option. Extend ConfigParser.set: check for string values."""
655-
if not isinstance(value, basestring):
655+
if not isinstance(value, str):
656656
raise TypeError("option values must be strings")
657657
# check for bad percent signs:
658658
# first, replace all "good" interpolations

Lib/UserString.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class UserString:
1313
def __init__(self, seq):
14-
if isinstance(seq, basestring):
14+
if isinstance(seq, str):
1515
self.data = seq
1616
elif isinstance(seq, UserString):
1717
self.data = seq.data[:]
@@ -66,12 +66,12 @@ def __getitem__(self, index): return self.__class__(self.data[index])
6666
def __add__(self, other):
6767
if isinstance(other, UserString):
6868
return self.__class__(self.data + other.data)
69-
elif isinstance(other, basestring):
69+
elif isinstance(other, str):
7070
return self.__class__(self.data + other)
7171
else:
7272
return self.__class__(self.data + str(other))
7373
def __radd__(self, other):
74-
if isinstance(other, basestring):
74+
if isinstance(other, str):
7575
return self.__class__(other + self.data)
7676
else:
7777
return self.__class__(str(other) + self.data)
@@ -184,7 +184,7 @@ def __setitem__(self, index, sub):
184184
if isinstance(index, slice):
185185
if isinstance(sub, UserString):
186186
sub = sub.data
187-
elif not isinstance(sub, basestring):
187+
elif not isinstance(sub, str):
188188
sub = str(sub)
189189
start, stop, step = index.indices(len(self.data))
190190
if step == -1:
@@ -221,7 +221,7 @@ def immutable(self):
221221
def __iadd__(self, other):
222222
if isinstance(other, UserString):
223223
self.data += other.data
224-
elif isinstance(other, basestring):
224+
elif isinstance(other, str):
225225
self.data += other
226226
else:
227227
self.data += str(other)

Lib/_abcoll.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ def count(self, value):
490490
return sum(1 for v in self if v == value)
491491

492492
Sequence.register(tuple)
493-
Sequence.register(basestring)
493+
Sequence.register(str)
494+
Sequence.register(str8)
494495
Sequence.register(memoryview)
495496

496497

Lib/binhex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def close(self):
169169
class BinHex:
170170
def __init__(self, name_finfo_dlen_rlen, ofp):
171171
name, finfo, dlen, rlen = name_finfo_dlen_rlen
172-
if isinstance(ofp, basestring):
172+
if isinstance(ofp, str):
173173
ofname = ofp
174174
ofp = io.open(ofname, 'wb')
175175
if os.name == 'mac':
@@ -371,7 +371,7 @@ def close(self):
371371

372372
class HexBin:
373373
def __init__(self, ifp):
374-
if isinstance(ifp, basestring):
374+
if isinstance(ifp, str):
375375
ifp = io.open(ifp, 'rb')
376376
#
377377
# Find initial colon.

Lib/cProfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def runcall(self, func, *args, **kw):
153153
# ____________________________________________________________
154154

155155
def label(code):
156-
if isinstance(code, basestring):
156+
if isinstance(code, str):
157157
return ('~', 0, code) # built-in functions ('~' sorts at the end)
158158
else:
159159
return (code.co_filename, code.co_firstlineno, code.co_name)

Lib/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def columnize(self, list, displaywidth=80):
356356
return
357357

358358
nonstrings = [i for i in range(len(list))
359-
if not isinstance(list[i], basestring)]
359+
if not isinstance(list[i], str)]
360360
if nonstrings:
361361
raise TypeError("list[i] not a string for i in %s"
362362
% ", ".join(map(str, nonstrings)))

Lib/cookielib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def split_header_words(header_values):
367367
[[('Basic', None), ('realm', '"foobar"')]]
368368
369369
"""
370-
assert not isinstance(header_values, basestring)
370+
assert not isinstance(header_values, str)
371371
result = []
372372
for text in header_values:
373373
orig_text = text

Lib/copy_reg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class found there. (This assumes classes don't modify their
114114
if "__slots__" in c.__dict__:
115115
slots = c.__dict__['__slots__']
116116
# if class has a single slot, it can be given as a string
117-
if isinstance(slots, basestring):
117+
if isinstance(slots, str):
118118
slots = (slots,)
119119
for name in slots:
120120
# special descriptors

Lib/decimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def __new__(cls, value="0", context=None):
588588

589589
# From a string
590590
# REs insist on real strings, so we can too.
591-
if isinstance(value, basestring):
591+
if isinstance(value, str):
592592
if _isinfinity(value):
593593
self._exp = 'F'
594594
self._int = (0,)

0 commit comments

Comments
 (0)