From 6669d427f87ec62a86a680a542d2f87f2d65cc80 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sat, 30 Mar 2024 22:16:37 +0100 Subject: Used PyCharms inspectors. --- libbe/command/base.py | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'libbe/command/base.py') diff --git a/libbe/command/base.py b/libbe/command/base.py index 806d880..b6a9e15 100644 --- a/libbe/command/base.py +++ b/libbe/command/base.py @@ -74,7 +74,7 @@ def get_command(command_name): >>> try: ... get_command('asdf') - ... except UnknownCommand, e: + ... except UnknownCommand as e: ... print(e) Unknown command 'asdf' (No module named asdf) @@ -99,7 +99,7 @@ def get_command_class(module=None, command_name=None): >>> repr(import_xml) "" """ - if module == None: + if module is None: module = get_command(command_name) try: cname = command_name.capitalize().replace('-', '_') @@ -121,7 +121,7 @@ def modname_to_command_name(modname): ... try: ... if issubclass(attr, Command): ... commands.append(attr) - ... except TypeError, e: + ... except TypeError as e: ... pass ... if len(commands) == 0: ... raise Exception('No Command classes in %s' % dir(mod)) @@ -163,7 +163,7 @@ class Argument (CommandInput): self.optional = optional self.repeatable = repeatable self.completion_callback = completion_callback - if self.metavar == None: + if self.metavar is None: self.metavar = self.name.upper() class Option (CommandInput): @@ -173,17 +173,17 @@ class Option (CommandInput): self.callback = callback self.short_name = short_name self.arg = arg - if self.arg == None and self.callback == None: + if self.arg is None and self.callback is None: # use an implicit boolean argument self.arg = Argument(name=self.name, help=self.help, default=False, type='bool') self.validate() def validate(self): - if self.arg == None: - assert self.callback != None, self.name + if self.arg is None: + assert self.callback is not None, self.name return - assert self.callback == None, '%s: %s' % (self.name, self.callback) + assert self.callback is None, '%s: %s' % (self.name, self.callback) assert self.arg.name == self.name, \ 'Name missmatch: %s != %s' % (self.arg.name, self.name) assert self.arg.optional == False, self.name @@ -208,13 +208,13 @@ class _DummyParser (optparse.OptionParser): # from libbe.ui.command_line.CmdOptionParser._add_option option.validate() long_opt = '--%s' % option.name - if option.short_name != None: + if option.short_name is not None: short_opt = '-%s' % option.short_name assert '_' not in option.name, \ 'Non-reconstructable option name %s' % option.name kwargs = {'dest':option.name.replace('-', '_'), 'help':option.help} - if option.arg == None or option.arg.type == 'bool': + if option.arg is None or option.arg.type == 'bool': kwargs['action'] = 'store_true' kwargs['metavar'] = None kwargs['default'] = False @@ -223,7 +223,7 @@ class _DummyParser (optparse.OptionParser): kwargs['action'] = 'store' kwargs['metavar'] = option.arg.metavar kwargs['default'] = option.arg.default - if option.short_name != None: + if option.short_name is not None: opt = optparse.Option(short_opt, long_opt, **kwargs) else: opt = optparse.Option(long_opt, **kwargs) @@ -291,7 +291,7 @@ class Command (object): pass else: params.pop('help') - if params['complete'] != None: + if params['complete'] is not None: pass else: params.pop('complete') @@ -303,16 +303,16 @@ class Command (object): return self.status def _parse_options_args(self, options=None, args=None): - if options == None: + if options is None: options = {} - if args == None: + if args is None: args = [] params = {} for option in self.options: assert option.name not in params, params[option.name] if option.name in options: params[option.name] = options.pop(option.name) - elif option.arg != None: + elif option.arg is not None: params[option.name] = option.arg.default else: # non-arg options are flags, set to default flag value params[option.name] = False @@ -385,13 +385,13 @@ class Command (object): return "A detailed help message." def complete(self, argument=None, fragment=None): - if argument == None: + if argument is None: ret = ['--%s' % o.name for o in self.options if o.name != 'complete'] - if len(self.args) > 0 and self.args[0].completion_callback != None: + if len(self.args) > 0 and self.args[0].completion_callback is not None: ret.extend(self.args[0].completion_callback(self, argument, fragment)) return ret - elif argument.completion_callback != None: + elif argument.completion_callback is not None: # finish a particular argument return argument.completion_callback(self, argument, fragment) return [] # the particular argument doesn't supply completion info @@ -413,7 +413,7 @@ class Command (object): >>> c = Command() >>> try: ... c._check_restricted_access(s, os.path.expanduser('~/.ssh/id_rsa')) - ... except UserError, e: + ... except UserError as e: ... assert str(e).startswith('file access restricted!'), str(e) ... print('we got the expected error') we got the expected error @@ -457,9 +457,9 @@ class StdInputOutput (InputOutput): InputOutput.__init__(self, stdin, stdout) def _get_io(self, input_encoding=None, output_encoding=None): - if input_encoding == None: + if input_encoding is None: input_encoding = libbe.util.encoding.get_input_encoding() - if output_encoding == None: + if output_encoding is None: output_encoding = libbe.util.encoding.get_output_encoding() stdin = codecs.getreader(input_encoding)(sys.stdin) stdin.encoding = input_encoding @@ -512,7 +512,7 @@ class UnconnectedStorageGetter (object): class StorageCallbacks (object): def __init__(self, location=None): - if location == None: + if location is None: location = '.' self.location = location self._get_unconnected_storage = UnconnectedStorageGetter(location) @@ -532,7 +532,7 @@ class StorageCallbacks (object): intended for the init command, which calls Storage.init(). """ if not hasattr(self, '_unconnected_storage'): - if self._get_unconnected_storage == None: + if self._get_unconnected_storage is None: raise NotImplementedError self._unconnected_storage = self._get_unconnected_storage() return self._unconnected_storage @@ -574,7 +574,7 @@ class StorageCallbacks (object): class UserInterface (object): def __init__(self, io=None, location=None): - if io == None: + if io is None: io = StringInputOutput() self.io = io self.storage_callbacks = StorageCallbacks(location) -- cgit