+class UnformattedLines(Line):
+ """Just like :class:`Line` but stores lines which aren't reformatted."""
+
+ def append(self, leaf: Leaf, preformatted: bool = True) -> None:
+ """Just add a new `leaf` to the end of the lines.
+
+ The `preformatted` argument is ignored.
+
+ Keeps track of indentation `depth`, which is useful when the user
+ says `# fmt: on`. Otherwise, doesn't do anything with the `leaf`.
+ """
+ try:
+ list(generate_comments(leaf))
+ except FormatOn as f_on:
+ self.leaves.append(f_on.leaf_from_consumed(leaf))
+ raise
+
+ self.leaves.append(leaf)
+ if leaf.type == token.INDENT:
+ self.depth += 1
+ elif leaf.type == token.DEDENT:
+ self.depth -= 1
+
+ def append_comment(self, comment: Leaf) -> bool:
+ """Not implemented in this class."""
+ raise NotImplementedError("Unformatted lines don't store comments separately.")
+
+ def maybe_remove_trailing_comma(self, closing: Leaf) -> bool:
+ """Does nothing and returns False."""
+ return False
+
+ def maybe_increment_for_loop_variable(self, leaf: Leaf) -> bool:
+ """Does nothing and returns False."""
+ return False
+
+ def maybe_adapt_standalone_comment(self, comment: Leaf) -> bool:
+ """Does nothing and returns False."""
+ return False
+
+ def __str__(self) -> str:
+ """Renders unformatted lines from leaves which were added with `append()`.
+
+ `depth` is not used for indentation in this case.
+ """
+ if not self:
+ return '\n'
+
+ res = ''
+ for leaf in self.leaves:
+ res += str(leaf)
+ return res
+
+