コード例 #1
0
    def format(self):

        yield from self.value.format()
        yield "["
        yield from self.slice.format()
        yield "]"
        yield from format_comment(self.line_comment)
コード例 #2
0
 def format(self):
     op = nothing()
     for v in self['values']:
         yield from op
         op = self.op.format()
         yield from v.format()
     yield from format_comment(self.line_comment)
コード例 #3
0
    def format(self):

        yield from emit_lines(self.decorator_list)
        yield "def"
        yield SPACE
        yield self.node.name
        yield "("
        yield from format_comment(self.line_comment)
        for a, d in zip_longest(self.args.args, self.args.defaults):
            yield a.arg
            if d:
                yield "="
                yield from d.format()
        yield "):"
        yield from format_comment(self.line_comment)
        yield CR
        yield from indent_body(self.body)
コード例 #4
0
 def format(self):
     yield from join(self.targets, ", ")
     yield SPACE
     yield "="
     yield SPACE
     yield from self.value.format()
     yield from format_comment(self.line_comment)
     yield CR
コード例 #5
0
    def format(self):

        yield "["
        yield from format_comment(self.line_comment)
        yield from self.elt.format()
        for g in self.generators:
            yield from g.format()
        yield "]"
コード例 #6
0
 def import_lines():
     for a in names:
         yield a.node.name
         if a.node.asname:
             yield SPACE
             yield "as"
             yield SPACE
             yield a.node.asname
         yield from format_comment(a.line_comment)
コード例 #7
0
    def format(self):

        yield from emit_lines(self.decorator_list)
        yield "async def " + self.node.name + "("
        yield from format_comment(self.line_comment)
        for a in self.node.args.args:
            yield a.arg
        yield ")"
        yield from self.body.format()
コード例 #8
0
    def format(self):

        yield "("
        yield from format_comment(self.line_comment)
        sep = None
        for v in self['elts']:
            yield sep
            sep = ", "
            yield from v.format()
        yield ")"
コード例 #9
0
    def format(self):
        value = self.node.value
        if isinstance(value, str):
            if self.is_multiline_string:
                yield '"""' + value + '"""'
            else:
                yield quote(value)
        elif isinstance(value, (float, int)):
            yield str(value)
        elif value is None:
            yield "None"
        elif isinstance(value, type(...)):
            yield "..."
        elif isinstance(value, bytes):
            yield repr(value)
        else:
            Log.error("do not know how to handle {{type}}",
                      type=value.__class__.__name__)

        format_comment(self.line_comment)
コード例 #10
0
    def format(self):

        yield "from"
        yield SPACE
        yield self.node.module
        yield SPACE
        yield "import"
        yield SPACE
        names = self.names
        if any(
                n.is_multiline(limit=120 - len(self.node.module) - 13)
                for n in names) or 120 < sum(len(n.name) for n in names) + len(
                    self.node.module) + 13:
            yield "("
            yield CR

            def import_lines():
                for a in names:
                    yield a.node.name
                    if a.node.asname:
                        yield SPACE
                        yield "as"
                        yield SPACE
                        yield a.node.asname
                    yield from format_comment(a.line_comment)

            yield from indent_lines(import_lines())
            yield CR
            yield ")"
            yield from format_comment(self.line_comment)

        else:
            # PACK THE IMPORT
            yield self.before_comment
            yield ", ".join(a.node.name +
                            (" as " + a.node.asname if a.node.asname else "")
                            for a in names)
            yield from format_comment(self.line_comment)

        yield CR
コード例 #11
0
    def format(self):

        yield "if"
        yield SPACE
        yield from self.test.format()
        yield ":"
        yield CR
        yield from format_comment(self.line_comment)
        yield from indent_body(self.body)
        if self.orelse:
            yield "else:"
            yield CR
            yield from indent_body(self.orelse)
コード例 #12
0
    def format(self):

        yield "try"
        yield from format_comment(self.line_comment)
        yield from self.body.format()
        for h in self.handlers:
            yield CR
            yield "except"
            yield SPACE
            yield h.type.node.id
            yield from format_comment(h.line_comment)
            yield from h.body.format()
        if self.orelse:
            yield CR
            yield "else"
            yield from format_comment(self.orelse.line_comment)
            yield from self.orelse.format()
        if self.finalbody:
            yield CR
            yield "finally"
            yield from format_comment(self.finalbody.line_comment)
            yield from self.finalbody.format()
コード例 #13
0
    def format(self):

        aliases = self.node.names
        for a in aliases:
            yield "import"
            yield SPACE
            yield a.name
            if a.asname:
                yield SPACE
                yield "as"
                yield SPACE
                yield a.asname
            yield from format_comment(self.line_comment)
        yield CR
コード例 #14
0
    def format(self):
        def items(separator=", "):
            sep = None
            for k, v in zip(self['keys'], self['values']):
                yield sep
                sep = separator
                yield from k.format()
                yield ": "
                yield from v.format()


        yield "{"
        yield from items(", ")
        yield "}"
        yield from format_comment(self.line_comment)
コード例 #15
0
    def format(self):

        yield SPACE
        yield "for"
        yield SPACE
        yield from self.target.format()
        yield SPACE
        yield "in"
        yield SPACE
        yield from self.iter.format()
        for i in self.ifs:
            yield SPACE
            yield "if"
            yield SPACE
            yield from i.format()
        yield from format_comment(self.line_comment)
コード例 #16
0
 def format(node):
     yield from emit_comments(node.before_comment)
     yield "async with "
     comma = False
     for w in node["items"]:
         if comma:
             yield ","
             yield SPACE
         comma = True
         yield from w.context_expr.format()
         if w.optional_vars:
             yield SPACE
             yield "as"
             yield SPACE
             yield w.optional_vars.id
     yield from format_comment(node.line_comment)
     yield from node.body.format()
コード例 #17
0
    def format(self):

        if self.is_decorator:
            yield "@"
        yield from self.func.format()
        yield "("
        comma = None
        for a in self.args:
            yield comma
            comma = ","
            yield SPACE
            yield from a.format()
        for a in self.keywords:
            yield comma
            comma = ","
            yield SPACE
            yield from a.format()
        yield ")"
        yield from format_comment(self.line_comment)
コード例 #18
0
 def format(self):
     yield from self.left.format()
     for o, c in zip(self.ops, self.comparators):
         yield from o.format()
         yield from c.format()
     yield from format_comment(self.line_comment)
コード例 #19
0
 def format(self):
     yield "["
     yield from csv(self['elts'])
     yield "]"
     yield from format_comment(self.line_comment)
コード例 #20
0
 def format(self):
     yield from self.op.format()
     yield from self.operand.format()
     yield from format_comment(self.line_comment)
コード例 #21
0
 def format(self):
     yield from self.left.format()
     yield from self.op.format()
     yield from self.right.format()
     yield from format_comment(self.line_comment)
コード例 #22
0
 def format(self):
     yield "pass"
     yield from format_comment(self.line_comment)
コード例 #23
0
    def format(self):

        yield from self.value.format()
        yield from format_comment(self.line_comment)
コード例 #24
0
 def format(self):
     yield "return"
     yield SPACE
     yield from self.value.format()
     yield from format_comment(self.line_comment)
     yield CR
コード例 #25
0
    def format(self):

        yield "continue"
        yield from format_comment(self.line_comment)