[issue44276] Replace if-elif-else structure with match-case (PEP634)
Raymond Hettinger
report at bugs.python.org
Tue Jun 1 20:06:36 EDT 2021
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
If the json.encoder code does get updated, it doesn't need two levels of matching. It can be flattened by eliminating the *chunks* variable.
match value:
case str():
yield _encoder(value)
case None:
yield 'null'
case True:
yield 'true'
case False:
yield 'false'
case int():
yield _intstr(value)
case float():
yield _floatstr(value)
case list() | tuple():
yield from _iterencode_list(value, _current_indent_level)
case dict():
yield from _iterencode_dict(value, _current_indent_level)
case _:
yield from _iterencode(value, _current_indent_level)
----------
nosy: +rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44276>
_______________________________________
More information about the Python-bugs-list
mailing list