示例#1
0
 def _convert_collections_namedtuple_args(self, node: ast3.Call):
   if len(node.args) != 2:
     msg = "Wrong args: expected namedtuple(name, [field, ...])"
     raise ParseError(msg)
   name, fields = node.args
   fields = self.convert_node(fields)
   fields = [(types.string_value(n), pytd.AnythingType()) for n in fields]
   node.args = [name.s, fields]  # pytype: disable=attribute-error
示例#2
0
 def _convert_typing_namedtuple_args(self, node: ast3.Call):
   # TODO(mdemello): handle NamedTuple("X", a=int, b=str, ...)
   if len(node.args) != 2:
     msg = "Wrong args: expected NamedTuple(name, [(field, type), ...])"
     raise ParseError(msg)
   name, fields = node.args
   fields = self.convert_node(fields)
   fields = [(types.string_value(n), t) for (n, t) in fields]
   node.args = [name.s, fields]
示例#3
0
 def _convert_typevar_args(self, node):
   self.annotation_visitor.visit(node.keywords)
   if not node.args:
     raise ParseError("Missing arguments to TypeVar")
   name, *rest = node.args
   if not isinstance(name, ast3.Str):
     raise ParseError("Bad arguments to TypeVar")
   node.args = [name.s] + [self.convert_node(x) for x in rest]
   # Special-case late types in bound since typeshed uses it.
   for kw in node.keywords:
     if kw.arg == "bound":
       if isinstance(kw.value, types.Pyval):
         val = types.string_value(kw.value, context="TypeVar bound")
         kw.value = self.annotation_visitor.convert_late_annotation(val)