diff options
author | Greg Noel <GregNoel@tigris.org> | 2010-03-27 07:39:52 (GMT) |
---|---|---|
committer | Greg Noel <GregNoel@tigris.org> | 2010-03-27 07:39:52 (GMT) |
commit | 59ed0a109bf5add2efcef459080837b11066c6fb (patch) | |
tree | fff879b4f9676a72e16c0f7b4dd969f050038b4f /src/engine/SCons/compat/_scons_optparse.py | |
parent | 00a3188193ba1feef927cf18e7f5fc20ad71b848 (diff) | |
download | SCons-59ed0a109bf5add2efcef459080837b11066c6fb.zip SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.gz SCons-59ed0a109bf5add2efcef459080837b11066c6fb.tar.bz2 |
http://scons.tigris.org/issues/show_bug.cgi?id=2329
Applied a number of idiomatic changes.
Uses of the 'sort()' method were converted into calls of 'sorted()' when
possible and the sorted() expression was inserted into a subsequent statement
whenever that made sense.
The statement 'while 1:' was changed to 'while True:'.
Names from the 'types' module (e.g., 'types.FooType') were converted to the
equivalent build-in type (e.g., 'foo').
Comparisons between types were changed to use 'isinstance()'.
Diffstat (limited to 'src/engine/SCons/compat/_scons_optparse.py')
-rw-r--r-- | src/engine/SCons/compat/_scons_optparse.py | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/engine/SCons/compat/_scons_optparse.py b/src/engine/SCons/compat/_scons_optparse.py index 5db4c90..ac5b448 100644 --- a/src/engine/SCons/compat/_scons_optparse.py +++ b/src/engine/SCons/compat/_scons_optparse.py @@ -643,8 +643,7 @@ class Option: else: setattr(self, attr, None) if attrs: - attrs = attrs.keys() - attrs.sort() + attrs = sorted(attrs.keys()) raise OptionError( "invalid keyword arguments: %s" % string.join(attrs, ", "), self) @@ -693,7 +692,7 @@ class Option: if self.choices is None: raise OptionError( "must supply a list of choices for type 'choice'", self) - elif type(self.choices) not in (types.TupleType, types.ListType): + elif type(self.choices) not in (tuple, list): raise OptionError( "choices must be a list of strings ('%s' supplied)" % string.split(str(type(self.choices)), "'")[1], self) @@ -737,12 +736,12 @@ class Option: raise OptionError( "callback not callable: %r" % self.callback, self) if (self.callback_args is not None and - type(self.callback_args) is not types.TupleType): + type(self.callback_args) is not tuple): raise OptionError( "callback_args, if supplied, must be a tuple: not %r" % self.callback_args, self) if (self.callback_kwargs is not None and - type(self.callback_kwargs) is not types.DictType): + type(self.callback_kwargs) is not dict): raise OptionError( "callback_kwargs, if supplied, must be a dict: not %r" % self.callback_kwargs, self) @@ -855,14 +854,13 @@ try: except NameError: (True, False) = (1, 0) -try: - types.UnicodeType -except AttributeError: +try: unicode +except NameError: def isbasestring(x): - return isinstance(x, types.StringType) + return isinstance(x, str) else: def isbasestring(x): - return isinstance(x, types.StringType) or isinstance(x, types.UnicodeType) + return isinstance(x, str) or isinstance(x, unicode) class Values: @@ -879,7 +877,7 @@ class Values: def __cmp__(self, other): if isinstance(other, Values): return cmp(self.__dict__, other.__dict__) - elif isinstance(other, types.DictType): + elif isinstance(other, dict): return cmp(self.__dict__, other) else: return -1 @@ -1040,7 +1038,7 @@ class OptionContainer: """add_option(Option) add_option(opt_str, ..., kwarg=val, ...) """ - if type(args[0]) is types.StringType: + if type(args[0]) is str: option = apply(self.option_class, args, kwargs) elif len(args) == 1 and not kwargs: option = args[0] @@ -1351,7 +1349,7 @@ class OptionParser (OptionContainer): def add_option_group(self, *args, **kwargs): # XXX lots of overlap with OptionContainer.add_option() - if type(args[0]) is types.StringType: + if type(args[0]) is str: group = apply(OptionGroup, (self,) + args, kwargs) elif len(args) == 1 and not kwargs: group = args[0] |