pylint/checkers/utils.py
def collect_string_fields(format_string) -> Iterable[Optional[str]]:
    """ Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.
    """
    formatter = string.Formatter()
    try:
        parseiterator = formatter.parse(format_string)
        for result in parseiterator:
            if all(item is None for item in result[1:]):
                # not a replacement format
                continue
            name = result[1]
            nested = result[2]
            yield name
            if nested:
                for field in collect_string_fields(nested):
                    yield field
    except ValueError as exc:
        # Probably the format string is invalid.
        if exc.args[0].startswith("cannot switch from manual"):
            # On Jython, parsing a string with both manual
            # and automatic positions will fail with a ValueError,
            # while on CPython it will simply return the fields,
            # the validation being done in the interpreter (?).
            # We're just returning two mixed fields in order
            # to trigger the format-combined-specification check.
            yield ""
            yield "1"
            return
        raise IncompleteFormatString(format_string)
def collect_string_fields(format_string) -> Iterable[Optional[str]]:
    """ Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.
    """
    formatter = string.Formatter()
    try:
        parseiterator = formatter.parse(format_string)
        for result in parseiterator:
            if all(item is None for item in result[1:]):
                # not a replacement format
                continue
            name = result[1]
            nested = result[2]
            yield name
            if nested:
                for field in collect_string_fields(nested):
                    yield field
    except ValueError as exc:
        # Probably the format string is invalid.
        if exc.args[0].startswith("cannot switch from manual"):
            # On Jython, parsing a string with both manual
            # and automatic positions will fail with a ValueError,
            # while on CPython it will simply return the fields,
            # the validation being done in the interpreter (?).
            # We're just returning two mixed fields in order
            # to trigger the format-combined-specification check.
            yield ""
            yield "1"
            return
        raise IncompleteFormatString(format_string)
def collect_string_fields ( format_string ) -> Iterable [ Optional [ str ] ] : formatter = string . Formatter ( ) try : parseiterator = formatter . parse ( format_string ) for result in parseiterator : if all ( item is None for item in result [ 1 : ] ) : # not a replacement format continue name = result [ 1 ] nested = result [ 2 ] yield name if nested : for field in collect_string_fields ( nested ) : yield field except ValueError as exc : # Probably the format string is invalid. if exc . args [ 0 ] . startswith ( "cannot switch from manual" ) : # On Jython, parsing a string with both manual # and automatic positions will fail with a ValueError, # while on CPython it will simply return the fields, # the validation being done in the interpreter (?). # We're just returning two mixed fields in order # to trigger the format-combined-specification check. yield "" yield "1" return raise IncompleteFormatString ( format_string )
Given a format string, return an iterator
    of all the valid format fields. It handles nested fields
    as well.
Given a format string return an iterator of all the valid format fields . It handles nested fields as well .