From beb655553bf6ec4b403bfe44c1e20073342285e0 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 11 Nov 2024 01:12:29 +0800 Subject: HALF WORK: 2024.1.20 --- tools/cru-py/cru/list.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tools/cru-py/cru/list.py') diff --git a/tools/cru-py/cru/list.py b/tools/cru-py/cru/list.py index e329ae2..9d210b7 100644 --- a/tools/cru-py/cru/list.py +++ b/tools/cru-py/cru/list.py @@ -1,7 +1,7 @@ from __future__ import annotations from collections.abc import Callable, Iterator -from typing import Any, Generic, Iterable, TypeAlias, TypeVar +from typing import Any, Generic, Iterable, TypeAlias, TypeVar, overload from ._error import CruInternalError from ._iter import CruIterator @@ -78,6 +78,14 @@ class CruUniqueKeyList(Generic[_T, _K]): if len(keys) != len(set(keys)): raise CruInternalError("Duplicate keys!") + @overload + def get_or( + self, key: _K, fallback: CruNotFound = CruNotFound.VALUE + ) -> _T | CruNotFound: ... + + @overload + def get_or(self, key: _K, fallback: _O) -> _T | _O: ... + def get_or( self, key: _K, fallback: _O | CruNotFound = CruNotFound.VALUE ) -> _T | _O | CruNotFound: -- cgit v1.2.3