How to use the result.Err function in result

To help you get started, we’ve selected a few result examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dbrgn / result / result / tests.py View on Github external
def test_ok_method():
    o = Ok('yay')
    n = Err('nay')
    assert o.ok() == 'yay'
    assert n.ok() is None
github dotnet / performance / src / benchmarks / gc / src / analysis / join_analysis.py View on Github external
def _sum_or_empty(i: Iterable[float]) -> FailableFloat:
    s = sum(i)
    return Err("empty join durations") if s == 0 else Ok(s)
github dotnet / performance / src / benchmarks / gc / src / analysis / process_trace.py View on Github external
def get_processed_trace_from_just_process(
    clr: Clr,
    trace_path: Path,
    p: AbstractTracedProcesses,
    process: AbstractTraceProcess,
    mang: AbstractTraceLoadedDotNetRuntime,
) -> ProcessedTrace:
    proc_info = get_process_info_from_mang(p, trace_path, process, trace_path.name, mang)
    return _init_processed_trace(
        ProcessedTrace(
            clr=clr,
            test_result=TestResult(trace_path=trace_path),
            test_status=Err("get_processed_trace_from_just_process has no test status"),
            process_info=proc_info,
            process_names=cast(ThreadToProcessToName, None),
            process_query=None,
            join_info=Err("did not request join info"),
            mechanisms_and_reasons=None,
            gcs_result=Err("temp"),
        ),
        proc_info,
    )
github dotnet / performance / src / benchmarks / gc / src / analysis / process_trace.py View on Github external
def _get_per_heap_histories(gc: AbstractTraceGC) -> Sequence[Result[str, AbstractGCPerHeapHistory]]:
    if gc.HeapCount == 1:
        return [Err("Workstation GC has no AbstractGCPerHeapHistories")]
    else:
        n = len(gc.PerHeapHistories)
        if n != gc.HeapCount:
            print(
                f"WARN: GC {gc.Number} has {gc.HeapCount} heaps, but {n} PerHeapHistories. It's a "
                + f" It's a {get_gc_kind_for_abstract_trace_gc(gc).name}."
            )
            return repeat(Err("GC has wrong number of PerHeapHistories"), gc.HeapCount)
        else:
            return [Ok(h) for h in gc.PerHeapHistories]
github dotnet / performance / src / benchmarks / gc / src / analysis / process_trace.py View on Github external
def _get_server_gc_heap_histories(
    gc: AbstractTraceGC
) -> Sequence[Result[str, AbstractServerGcHistory]]:
    if gc.HeapCount == 1:
        return [Err("Workstation GC has no ServerGcHeapHistories")]
    else:
        n = len(gc.ServerGcHeapHistories)
        if n != gc.HeapCount:
            print(
                f"WARN: GC {gc.Number} has {gc.HeapCount} heaps, but {n} ServerGcHeapHistories."
                + f" It's a {get_gc_kind_for_abstract_trace_gc(gc).name}."
            )
            return repeat(Err("GC has wrong number of ServerGcHeapHistories"), gc.HeapCount)
        else:
            return [Ok(h) for h in gc.ServerGcHeapHistories]
github Pinafore / qb / qanta / ingestion / annotated_mapping.py View on Github external
def _check_page_in_titles(self, maybe_page: Result[str, str]) -> Result[str, str]:
        if maybe_page.is_err():
            return maybe_page
        else:
            page = maybe_page.ok().replace(' ', '_')
            if page in self._wiki_titles:
                return Ok(page)
            else:
                return Err(f'page="{page}" not in wikipedia titles')
github Pinafore / qb / qanta / ingestion / annotated_mapping.py View on Github external
maybe_page = None
            word_set = set(words)
            for m in matches:
                page_words = m['words']
                for w in page_words:
                    if w in word_set:
                        if maybe_page is None:
                            maybe_page = m['page']
                            break
                        else:
                            return Err(
                                f'More than one match found: "{maybe_page}" and "{m["page"]}" for A: "{answer}" W: "'
                                f'{words}"'
                            )
            if maybe_page is None:
                return Err('No match found')
            else:
                return Ok(maybe_page)

        else:
            return Err('No match found')
github dotnet / performance / src / benchmarks / gc / src / analysis / process_trace.py View on Github external
clr: Clr,
    trace_path: Path,
    p: AbstractTracedProcesses,
    process: AbstractTraceProcess,
    mang: AbstractTraceLoadedDotNetRuntime,
) -> ProcessedTrace:
    proc_info = get_process_info_from_mang(p, trace_path, process, trace_path.name, mang)
    return _init_processed_trace(
        ProcessedTrace(
            clr=clr,
            test_result=TestResult(trace_path=trace_path),
            test_status=Err("get_processed_trace_from_just_process has no test status"),
            process_info=proc_info,
            process_names=cast(ThreadToProcessToName, None),
            process_query=None,
            join_info=Err("did not request join info"),
            mechanisms_and_reasons=None,
            gcs_result=Err("temp"),
        ),
        proc_info,
    )