Author Kshitiz17
Recipients Kshitiz17, brandtbucher, xtreak
Date 2021-06-01.10:22:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1622542921.92.0.580186585443.issue44276@roundup.psfhosted.org>
In-reply-to
Content
This is a relatively simple example of how this will improve readability of the code.
(This example is form Lib/json/encoder.py)

Original

-------------------------------------------------------------------------
    if isinstance(value, str):
        yield _encoder(value)
    elif value is None:
        yield 'null'
    elif value is True:
        yield 'true'
    elif value is False:
        yield 'false'
    elif isinstance(value, int):
        yield _intstr(value)
    elif isinstance(value, float):
        yield _floatstr(value)
    else:
        if isinstance(value, (list, tuple)):
            chunks = _iterencode_list(value, _current_indent_level)
        elif isinstance(value, dict):
            chunks = _iterencode_dict(value, _current_indent_level)
        else:
            chunks = _iterencode(value, _current_indent_level)
        yield from chunks 
--------------------------------------------------------------------------

Suggested

--------------------------------------------------------------------------
    match value:
        case str():
            yield _encoder(value)
        case None:
            yield 'null'
        case True:
            yield 'true'
        case False:
            yield 'false'
        case int():
            # see comment for int/float in _make_iterencode
            yield _intstr(value)
        case float():
            # see comment for int/float in _make_iterencode
            yield _floatstr(value)
        case _:
            match value:
                case list()|tuple():
                    chunks = _iterencode_list(value, _current_indent_level)
                case dict():
                    chunks = _iterencode_dict(value, _current_indent_level)
                case _:
                    chunks = _iterencode(value, _current_indent_level)
            yield from chunks
----------------------------------------------------------------------------
History
Date User Action Args
2021-06-01 10:22:01Kshitiz17setrecipients: + Kshitiz17, xtreak, brandtbucher
2021-06-01 10:22:01Kshitiz17setmessageid: <1622542921.92.0.580186585443.issue44276@roundup.psfhosted.org>
2021-06-01 10:22:01Kshitiz17linkissue44276 messages
2021-06-01 10:22:01Kshitiz17create