def collect_string_fields(format_string) -> Iterable[Optional[str]]:
formatter = string.Formatter()<EOL>try:<EOL><INDENT>parseiterator = formatter.parse(format_string)<EOL>for result in parseiterator:<EOL><INDENT>if all(item is None for item in result[<NUM_LIT:1>:]):<EOL><INDENT>continue<EOL><DEDENT>name = result[<NUM_LIT:1>]<EOL>nested = result[<NUM_LIT:2>]<EOL>yield name<EOL>if nested:<EOL><INDENT>for field in collect_string_fields(nested):<EOL><INDENT>yield field<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except ValueError as exc:<EOL><INDENT>if exc.args[<NUM_LIT:0>].startswith("<STR_LIT>"):<EOL><INDENT>yield "<STR_LIT>"<EOL>yield "<STR_LIT:1>"<EOL>return<EOL><DEDENT>raise IncompleteFormatString(format_string)<EOL><DEDENT>
Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.