def clean_stacks(self, stacks: List[List[BaseLayer]])-> List[List[BaseLayer]]:
ns: List[List[BaseLayer]] = []<EOL>for stack in stacks:<EOL><INDENT>if isinstance(stack[-<NUM_LIT:1>], lyr.Sleep):<EOL><INDENT>ns.extend([x] for x in stack)<EOL><DEDENT>else:<EOL><INDENT>ns.append([x for x in stack if not isinstance(x, lyr.Sleep)])<EOL><DEDENT><DEDENT>if not ns:<EOL><INDENT>return ns<EOL><DEDENT>last = ns[-<NUM_LIT:1>]<EOL>if len(last) == <NUM_LIT:1> and isinstance(last[<NUM_LIT:0>], lyr.Sleep):<EOL><INDENT>return ns[:-<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>return ns<EOL><DEDENT>
Two cases: if a stack finishes by a sleep then let's keep it (it means
that there was nothing after the text). However if the stack finishes
with something else (like a quick reply) then we don't risk an
is preserved.