Beispiel #1
0
def GetBuiltins():
  """Get the "default" AST used to lookup built in types.

  Get an AST for all Python builtins as well as the most commonly used standard
  libraries.

  Returns:
    A pytd.TypeDeclUnit instance. It'll directly contain the builtin classes
    and functions, and submodules for each of the standard library modules.
  """
  builtins = parser.parse_file(utils.GetDataFile("builtins/__builtin__.pytd"))
  for mod in [
      "array", "errno", "fcntl", "gc", "itertools", "marshal", "posix", "pwd",
      "select", "signal", "_sre", "_struct", "strop", "sys", "_warnings",
      "_weakref"]:
    builtins.modules[mod] = parser.parse_file(
        utils.GetDataFile("builtins/" + mod + ".pytd"))
  return builtins
Beispiel #2
0
 def setUp(self):
   with open(utils.GetDataFile("examples/StringIO.py"), "r") as infile:
     self.ty = self.Infer(infile.read())
   try:
     self.stringio_cls = self.ty.Lookup("StringIO")
   except KeyError:
     self.stringio_cls = None
     # Continue to the test it will fail if it needs the cls
   self.stringio_type = pytd.ClassType("StringIO")
   self.stringio_type.cls = self.stringio_cls
Beispiel #3
0
 def setUp(self):
   with open(utils.GetDataFile("examples/pytree.py"), "r") as infile:
     self.ty = self.Infer(infile.read())
Beispiel #4
0
 def testGetDataFileReturnsString(self):
     # smoke test, only checks that it doesn't throw and the result is a string
     self.assertIsInstance(utils.GetDataFile("builtins/errno.pytd"), str)
Beispiel #5
0
def _FindBuiltinFile(name):
    return utils.GetDataFile(os.path.join("builtins", name))