INNER CODE UNIT · Python

fix_repeating_arguments

KwaiAppTeam/KOOM · koom-common/kwai-android-base/src/main/cpp/fmtlib/support/docopt.py:57

    def fix_repeating_arguments(self):
        """Fix elements that should accumulate/increment values."""
        either = [list(child.children) for child in transform(self).children]
        for case in either:
            for e in [child for child in case if case.count(child) > 1]:
                if type(e) is Argument or type(e) is Option and e.argcount:
                    if e.value is None:
                        e.value = []
                    elif type(e.value) is not list:
                        e.value = e.value.split()
                if type(e) is Command or type(e) is Option and e.argcount == 0:
                    e.value = 0
        return self


def transform(pattern):
    """Expand pattern into an (almost) equivalent one, but with single Either.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…