In general, it seems like a bad practice to mutate input parameters. However, text["format"] = _type_to_text_format_param(text_format) does exactly this. See peter-zhong-replit@1e949be for potential ...
"Dictionaries are sorted by key before the display is computed" is not correct. The sort_dicts parameter is discussed in more detail further down in the documentation of each method where it matters.