<commit_before>import os
from subprocess import CompletedProcess
from typing import Mapping

from .exc import RunCommandsError
from .util import cached_property


class Result(RunCommandsError):

    def __init__(self, args, return_code, stdout, stderr):
        self.args = args
        self.return_code = return_code
        self.stdout = stdout
        self.stderr = stderr
        self.succeeded = self.return_code == 0
        self.failed = not self.succeeded

    @classmethod
    def from_subprocess_result(cls, result: CompletedProcess):
        return cls(
            result.args,
            result.returncode,
            result.stdout,
            result.stderr,
        )

    @cached_property
    def args_str(self):
        args = self.args
        if isinstance(args, str):
            return args
        if isinstance(args, Mapping):
            return ' '.join(
                '{0} => {1}'.format(item) for item in args.items()
            )
        # XXX: Assume list, tuple, or some other kind of sequence<commit_msg>Convert Result args to list when str<commit_after>import os
import shlex
from subprocess import CompletedProcess
from typing import Mapping

from .exc import RunCommandsError
from .util import cached_property


class Result(RunCommandsError):

    def __init__(self, args, return_code, stdout, stderr):
        args = shlex.split(args) if isinstance(args, str) else args
        self.args = args
        self.return_code = return_code
        self.stdout = stdout
        self.stderr = stderr
        self.succeeded = self.return_code == 0
        self.failed = not self.succeeded

    @classmethod
    def from_subprocess_result(cls, result: CompletedProcess):
        return cls(
            result.args,
            result.returncode,
            result.stdout,
            result.stderr,
        )

    @cached_property
    def args_str(self):
        args = self.args
        if isinstance(args, Mapping):
            return ' '.join(
                '{0} => {1}'.format(item) for item in args.items()
            )
        # XXX: Assume list, tuple, or some other kind of sequence
{'fraction_non_alphanumeric': 0.08043273753527752, 'fraction_numerical': 0.0028222013170272815, 'mean_word_length': 2.179372197309417, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4700561', 'n_tokens_mistral': 592, 'n_tokens_neox': 579, 'n_words': 173}