else: # could be Subscript, Call or many more
return None
+ def _is_list_or_tuple(self, obj):
+ return isinstance(obj, ast.List) or isinstance(obj, ast.Tuple)
+
def visit_Call(self, node):
"""Look for the register_opt/register_opts calls."""
# extract the obj_name and method_name
return (super(CheckOptRegistrationArgs,
self).generic_visit(node))
- # argument should be a list with register_opts()
if len(node.args) > 0:
argument_name = self._find_name(node.args[0])
if argument_name:
# passing in a variable referencing the options being
# registered.
if (method_name == self.singular_method and
- (isinstance(node.args[0], ast.List)) or
- isinstance(node.args[0], ast.Tuple)):
+ self._is_list_or_tuple(node.args[0])):
self.add_error(node.args[0])
- elif (method_name == self.plural_method and
- (not isinstance(node.args[0], ast.List)) or
- isinstance(node.args[0], ast.Tuple)):
+ elif (method_name == self.plural_method and not
+ self._is_list_or_tuple(node.args[0])):
self.add_error(node.args[0])
return super(CheckOptRegistrationArgs, self).generic_visit(node)
checker = checks.CheckOptRegistrationArgs
code = """
CONF.register_opts([opt1, opt2, opt3])
+ CONF.register_opts((opt4, opt5))
CONF.register_opt(lonely_opt)
CONF.register_opts([OPT1, OPT2], group="group_of_opts")
CONF.register_opt(single_opt, group=blah)
code = """
CONF.register_opt([opt4, opt5, opt6])
+ CONF.register_opt((opt7, opt8))
CONF.register_opts(lonely_opt)
CONF.register_opt((an_opt, another_opt))
"""
- for method in checker.register_methods:
- self._assert_has_errors(code.format(method), checker,
- expected_errors=[(1, 18, 'C311'),
- (2, 19, 'C311'),
- (3, 19, 'C311')])
+ self._assert_has_errors(code, checker,
+ expected_errors=[(1, 18, 'C311'),
+ (2, 19, 'C311'),
+ (3, 19, 'C311'),
+ (4, 19, 'C311')])
code = """
CONF.register_opt(single_opt)