Skip to content

Commit 572dbf8

Browse files
committed
Checkpoint. Manipulated things so that string literals are always
unicode, and a few other compensating changes, e.g. str <- unicode, chr <- unichr, and repr() of a unicode string no longer starts with 'u'. Lots of unit tests are broken, but some basic things work, in particular distutils works so the extensions can be built, and test_builtin.py works.
1 parent d4617f2 commit 572dbf8

28 files changed

+68
-81
lines changed

Include/pydebug.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ PyAPI_DATA(int) Py_NoSiteFlag;
1414
PyAPI_DATA(int) Py_UseClassExceptionsFlag;
1515
PyAPI_DATA(int) Py_FrozenFlag;
1616
PyAPI_DATA(int) Py_TabcheckFlag;
17-
PyAPI_DATA(int) Py_UnicodeFlag;
1817
PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
1918
PyAPI_DATA(int) Py_DivisionWarningFlag;
2019

Lib/distutils/ccompiler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class (via the 'executables' class attribute), but most will have:
168168
# set_executables ()
169169

170170
def set_executable(self, key, value):
171-
if type(value) is StringType:
171+
if isinstance(value, basestring):
172172
setattr(self, key, split_quoted(value))
173173
else:
174174
setattr(self, key, value)
@@ -193,8 +193,8 @@ def _check_macro_definitions (self, definitions):
193193
if not (type (defn) is TupleType and
194194
(len (defn) == 1 or
195195
(len (defn) == 2 and
196-
(type (defn[1]) is StringType or defn[1] is None))) and
197-
type (defn[0]) is StringType):
196+
(isinstance (defn[1], basestring) or defn[1] is None))) and
197+
isinstance (defn[0], basestring)):
198198
raise TypeError, \
199199
("invalid macro definition '%s': " % defn) + \
200200
"must be tuple (string,), (string, string), or " + \
@@ -344,7 +344,7 @@ def _setup_compile(self, outdir, macros, incdirs, sources, depends,
344344
"""
345345
if outdir is None:
346346
outdir = self.output_dir
347-
elif type(outdir) is not StringType:
347+
elif not isinstance(outdir, basestring):
348348
raise TypeError, "'output_dir' must be a string or None"
349349

350350
if macros is None:
@@ -442,7 +442,7 @@ def _fix_compile_args (self, output_dir, macros, include_dirs):
442442
"""
443443
if output_dir is None:
444444
output_dir = self.output_dir
445-
elif type (output_dir) is not StringType:
445+
elif not isinstance(output_dir, basestring):
446446
raise TypeError, "'output_dir' must be a string or None"
447447

448448
if macros is None:
@@ -527,7 +527,7 @@ def _fix_object_args (self, objects, output_dir):
527527

528528
if output_dir is None:
529529
output_dir = self.output_dir
530-
elif type (output_dir) is not StringType:
530+
elif not isinstance(output_dir, basestring):
531531
raise TypeError, "'output_dir' must be a string or None"
532532

533533
return (objects, output_dir)

Lib/distutils/cmd.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def _ensure_stringlike (self, option, what, default=None):
222222
if val is None:
223223
setattr(self, option, default)
224224
return default
225-
elif type(val) is not StringType:
225+
elif not isinstance(val, basestring):
226226
raise DistutilsOptionError, \
227227
"'%s' must be a %s (got `%s`)" % (option, what, val)
228228
return val
@@ -242,12 +242,11 @@ def ensure_string_list (self, option):
242242
val = getattr(self, option)
243243
if val is None:
244244
return
245-
elif type(val) is StringType:
245+
elif isinstance(val, basestring):
246246
setattr(self, option, re.split(r',\s*|\s+', val))
247247
else:
248248
if type(val) is ListType:
249-
types = map(type, val)
250-
ok = (types == [StringType] * len(val))
249+
ok = all(isinstance(v, basestring) for v in val)
251250
else:
252251
ok = 0
253252

@@ -421,7 +420,7 @@ def make_file (self, infiles, outfile, func, args,
421420

422421

423422
# Allow 'infiles' to be a single string
424-
if type(infiles) is StringType:
423+
if isinstance(infiles, basestring):
425424
infiles = (infiles,)
426425
elif type(infiles) not in (ListType, TupleType):
427426
raise TypeError, \

Lib/distutils/command/build_clib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def finalize_options (self):
9292

9393
if self.include_dirs is None:
9494
self.include_dirs = self.distribution.include_dirs or []
95-
if type(self.include_dirs) is StringType:
95+
if isinstance(self.include_dirs, basestring):
9696
self.include_dirs = self.include_dirs.split(os.pathsep)
9797

9898
# XXX same as for build_ext -- what about 'self.define' and
@@ -147,7 +147,7 @@ def check_library_list (self, libraries):
147147
raise DistutilsSetupError, \
148148
"each element of 'libraries' must a 2-tuple"
149149

150-
if type(lib[0]) is not StringType:
150+
if isinstance(lib[0], basestring) StringType:
151151
raise DistutilsSetupError, \
152152
"first element of each tuple in 'libraries' " + \
153153
"must be a string (the library name)"

Lib/distutils/command/build_ext.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def finalize_options (self):
137137
plat_py_include = sysconfig.get_python_inc(plat_specific=1)
138138
if self.include_dirs is None:
139139
self.include_dirs = self.distribution.include_dirs or []
140-
if type(self.include_dirs) is StringType:
140+
if isinstance(self.include_dirs, basestring):
141141
self.include_dirs = self.include_dirs.split(os.pathsep)
142142

143143
# Put the Python "system" include dir at the end, so that
@@ -146,7 +146,7 @@ def finalize_options (self):
146146
if plat_py_include != py_include:
147147
self.include_dirs.append(plat_py_include)
148148

149-
if type(self.libraries) is StringType:
149+
if isinstance(self.libraries, basestring):
150150
self.libraries = [self.libraries]
151151

152152
# Life is easier if we're not forever checking for None, so
@@ -155,12 +155,12 @@ def finalize_options (self):
155155
self.libraries = []
156156
if self.library_dirs is None:
157157
self.library_dirs = []
158-
elif type(self.library_dirs) is StringType:
158+
elif isinstance(self.library_dirs, basestring):
159159
self.library_dirs = self.library_dirs.split(os.pathsep)
160160

161161
if self.rpath is None:
162162
self.rpath = []
163-
elif type(self.rpath) is StringType:
163+
elif isinstance(self.rpath, basestring):
164164
self.rpath = self.rpath.split(os.pathsep)
165165

166166
# for extensions under windows use different directories
@@ -321,7 +321,7 @@ def check_extensions_list (self, extensions):
321321
("each element of 'ext_modules' option must be an "
322322
"Extension instance or 2-tuple")
323323

324-
if not (type(ext_name) is StringType and
324+
if not (isinstance(ext_name, basestring) and
325325
extension_name_re.match(ext_name)):
326326
raise DistutilsSetupError, \
327327
("first element of each tuple in 'ext_modules' "

Lib/distutils/command/build_py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def get_outputs (self, include_bytecode=1):
361361

362362

363363
def build_module (self, module, module_file, package):
364-
if type(package) is StringType:
364+
if isinstance(package, basestring):
365365
package = package.split('.')
366366
elif type(package) not in (ListType, TupleType):
367367
raise TypeError, \

Lib/distutils/command/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@ def initialize_options (self):
7373
def finalize_options (self):
7474
if self.include_dirs is None:
7575
self.include_dirs = self.distribution.include_dirs or []
76-
elif type(self.include_dirs) is StringType:
76+
elif isinstance(self.include_dirs, basestring):
7777
self.include_dirs = self.include_dirs.split(os.pathsep)
7878

7979
if self.libraries is None:
8080
self.libraries = []
81-
elif type(self.libraries) is StringType:
81+
elif isinstance(self.libraries, basestring):
8282
self.libraries = [self.libraries]
8383

8484
if self.library_dirs is None:
8585
self.library_dirs = []
86-
elif type(self.library_dirs) is StringType:
86+
elif isinstance(self.library_dirs, basestring):
8787
self.library_dirs = self.library_dirs.split(os.pathsep)
8888

8989

@@ -212,7 +212,7 @@ def search_cpp (self, pattern, body=None,
212212
self._check_compiler()
213213
(src, out) = self._preprocess(body, headers, include_dirs, lang)
214214

215-
if type(pattern) is StringType:
215+
if isinstance(pattern, basestring):
216216
pattern = re.compile(pattern)
217217

218218
file = open(out)

Lib/distutils/command/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def handle_extra_path (self):
463463
self.extra_path = self.distribution.extra_path
464464

465465
if self.extra_path is not None:
466-
if type(self.extra_path) is StringType:
466+
if isinstance(self.extra_path, basestring):
467467
self.extra_path = self.extra_path.split(',')
468468

469469
if len(self.extra_path) == 1:

Lib/distutils/command/install_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
__revision__ = "$Id$"
1111

1212
import os
13-
from types import StringType
1413
from distutils.core import Command
1514
from distutils.util import change_root, convert_path
1615

@@ -48,7 +47,7 @@ def finalize_options (self):
4847
def run (self):
4948
self.mkpath(self.install_dir)
5049
for f in self.data_files:
51-
if type(f) is StringType:
50+
if isinstance(f, basestring):
5251
# it's a simple file, so copy it
5352
f = convert_path(f)
5453
if self.warn_dir:

Lib/distutils/dir_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def mkpath (name, mode=0777, verbose=0, dry_run=0):
3131
global _path_created
3232

3333
# Detect a common bug -- name is None
34-
if not isinstance(name, StringTypes):
34+
if not isinstance(name, basestring):
3535
raise DistutilsInternalError, \
3636
"mkpath: 'name' must be a string (got %r)" % (name,)
3737

Lib/distutils/dist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,13 @@ def finalize_options (self):
598598

599599
keywords = self.metadata.keywords
600600
if keywords is not None:
601-
if type(keywords) is StringType:
601+
if isinstance(keywords, basestring):
602602
keywordlist = keywords.split(',')
603603
self.metadata.keywords = [x.strip() for x in keywordlist]
604604

605605
platforms = self.metadata.platforms
606606
if platforms is not None:
607-
if type(platforms) is StringType:
607+
if isinstance(platforms, basestring):
608608
platformlist = platforms.split(',')
609609
self.metadata.platforms = [x.strip() for x in platformlist]
610610

@@ -906,7 +906,7 @@ def _set_command_options (self, command_obj, option_dict=None):
906906
neg_opt = {}
907907

908908
try:
909-
is_string = type(value) is StringType
909+
is_string = isinstance(value, basestring)
910910
if option in neg_opt and is_string:
911911
setattr(command_obj, neg_opt[option], not strtobool(value))
912912
elif option in bool_opts and is_string:

Lib/distutils/extension.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def __init__ (self, name, sources,
103103
language=None,
104104
**kw # To catch unknown keywords
105105
):
106-
assert type(name) is StringType, "'name' must be a string"
106+
assert isinstance(name, basestring), "'name' must be a string"
107107
assert (type(sources) is ListType and
108-
map(type, sources) == [StringType]*len(sources)), \
108+
all(isinstance(v, basestring) for v in sources)), \
109109
"'sources' must be a list of strings"
110110

111111
self.name = name

Lib/distutils/fancy_getopt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ def _grok_option_table (self):
166166
raise ValueError, "invalid option tuple: %r" % (option,)
167167

168168
# Type- and value-check the option names
169-
if type(long) is not StringType or len(long) < 2:
169+
if not isinstance(long, basestring) or len(long) < 2:
170170
raise DistutilsGetoptError, \
171171
("invalid long option '%s': "
172172
"must be a string of length >= 2") % long
173173

174174
if (not ((short is None) or
175-
(type(short) is StringType and len(short) == 1))):
175+
(isinstance(short, basestring) and len(short) == 1))):
176176
raise DistutilsGetoptError, \
177177
("invalid short option '%s': "
178178
"must a single character or None") % short

Lib/distutils/filelist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def translate_pattern (pattern, anchor=1, prefix=None, is_regex=0):
333333
or just returned as-is (assumes it's a regex object).
334334
"""
335335
if is_regex:
336-
if type(pattern) is StringType:
336+
if isinstance(pattern, basestring):
337337
return re.compile(pattern)
338338
else:
339339
return pattern

Lib/distutils/unixccompiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
__revision__ = "$Id$"
1717

1818
import os, sys
19-
from types import StringType, NoneType
19+
from types import NoneType
2020
from copy import copy
2121

2222
from distutils import sysconfig
@@ -212,7 +212,7 @@ def link(self, target_desc, objects,
212212

213213
lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,
214214
libraries)
215-
if type(output_dir) not in (StringType, NoneType):
215+
if not isinstance(output_dir, (basestring, NoneType)):
216216
raise TypeError, "'output_dir' must be a string or None"
217217
if output_dir is not None:
218218
output_filename = os.path.join(output_dir, output_filename)

Lib/locale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def setlocale(category, locale=None):
470470
category may be given as one of the LC_* values.
471471
472472
"""
473-
if locale and type(locale) is not type(""):
473+
if locale and not isinstance(locale, basestring):
474474
# convert to string
475475
locale = normalize(_build_localename(locale))
476476
return _setlocale(category, locale)

Lib/os.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,8 @@ def urandom(n):
733733
_urandomfd = open("/dev/urandom", O_RDONLY)
734734
except (OSError, IOError):
735735
raise NotImplementedError("/dev/urandom (or equivalent) not found")
736-
bytes = ""
737-
while len(bytes) < n:
738-
bytes += read(_urandomfd, n - len(bytes))
736+
bs = b""
737+
while len(bs) < n:
738+
bs += read(_urandomfd, n - len(bs))
739739
close(_urandomfd)
740-
return bytes
740+
return bs

Lib/sre_compile.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,8 @@ def _compile_info(code, pattern, flags):
470470
_compile_charset(charset, flags, code)
471471
code[skip] = len(code) - skip
472472

473-
try:
474-
unicode
475-
except NameError:
476-
STRING_TYPES = (type(""),)
477-
else:
478-
STRING_TYPES = (type(""), type(unicode("")))
479-
480473
def isstring(obj):
481-
for tp in STRING_TYPES:
482-
if isinstance(obj, tp):
483-
return 1
484-
return 0
474+
return isinstance(obj, basestring)
485475

486476
def _code(p, flags):
487477

0 commit comments

Comments
 (0)