def nits()

in contrib/python/src/python/pants/contrib/python/checks/checker/variable_names.py [0:0]


  def nits(self):
    class_methods = set()
    all_methods = {function_def for function_def in ast.walk(self.python_file.tree)
                   if isinstance(function_def, ast.FunctionDef)}

    for class_def in self.iter_ast_types(ast.ClassDef):
      if not is_upper_camel(class_def.name):
        yield self.error('T000', 'Classes must be UpperCamelCased', class_def)
      for class_global in self.iter_class_globals(class_def):
        if not is_constant(class_global.id) and class_global.id not in self.CLASS_GLOBAL_BUILTINS:
          yield self.error('T001', 'Class globals must be UPPER_SNAKE_CASED', class_global)
      if not class_def.bases or all(isinstance(base, ast.Name) and base.id == 'object'
          for base in class_def.bases):
        class_methods.update(self.iter_class_methods(class_def))
      else:
        # If the class is inheriting from anything that is potentially a bad actor, rely
        # upon checking that bad actor out of band.  Fixes PANTS-172.
        for method in self.iter_class_methods(class_def):
          all_methods.discard(method)

    for function_def in all_methods - class_methods:
      if is_reserved_name(function_def.name):
        yield self.error('T801', 'Method name overrides a builtin.', function_def)

    # TODO(wickman) Only enforce this for classes that derive from object.  If they
    # don't derive object, it's possible that the superclass naming is out of its
    # control.
    for function_def in all_methods:
      if not any((is_lower_snake(function_def.name),
                  is_builtin_name(function_def.name),
                  is_reserved_with_trailing_underscore(function_def.name))):
        yield self.error('T002', 'Method names must be lower_snake_cased', function_def)