Exemple #1
0
    def testIsClasssAttr(self):
        result = parser.is_class_attr('test_module.test_function',
                                      {'test_module': test_module})
        self.assertFalse(result)

        result = parser.is_class_attr('TestClass.test_function',
                                      {'TestClass': TestClass})
        self.assertTrue(result)
Exemple #2
0
  def from_visitor(cls, visitor, **kwargs):
    """A factory function for building a ReferenceResolver from a visitor.

    Args:
      visitor: an instance of `DocGeneratorVisitor`
      **kwargs: all remaining args are passed to the constructor

    Returns:
      an instance of `ReferenceResolver` ()
    """
    is_fragment = {}
    for full_name, obj in visitor.index.items():
      obj_type = obj_type_lib.ObjType.get(obj)
      if obj_type in (obj_type_lib.ObjType.CLASS, obj_type_lib.ObjType.MODULE):
        is_fragment[full_name] = False
      elif obj_type in (obj_type_lib.ObjType.CALLABLE,
                        obj_type_lib.ObjType.TYPE_ALIAS):
        if parser.is_class_attr(full_name, visitor.index):
          is_fragment[full_name] = True
        else:
          is_fragment[full_name] = False
      else:
        is_fragment[full_name] = True

    return cls(
        duplicate_of=visitor.duplicate_of, is_fragment=is_fragment, **kwargs)