# Copyright 2022-2026 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
import io
import re
import textwrap
[docs]
def when_order(when: str):
"""Sort 'when' conditions consistently when unpacking from sets or lists"""
if not when:
return (3, when) # Handle empty strings
first_char = when[0]
if first_char.isalpha():
priority = 0
elif first_char == "+":
priority = 1
elif first_char == "~":
priority = 2
else:
priority = 3 # For any other characters
return (priority, when)