diff options
author | crupest <crupest@outlook.com> | 2024-11-11 01:12:29 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-01-20 15:06:20 +0800 |
commit | 12e1272508ba0b5909069319007d677c1c76e355 (patch) | |
tree | 969e16dea577b4cbc427791de60083a6c962c1c6 /tools/cru-py/cru/list.py | |
parent | fc6cd0846eae8c7f7a50e18b654b1f14f7b7840f (diff) | |
download | crupest-12e1272508ba0b5909069319007d677c1c76e355.tar.gz crupest-12e1272508ba0b5909069319007d677c1c76e355.tar.bz2 crupest-12e1272508ba0b5909069319007d677c1c76e355.zip |
HALF WORK: 2024.1.20
Diffstat (limited to 'tools/cru-py/cru/list.py')
-rw-r--r-- | tools/cru-py/cru/list.py | 10 |
1 files changed, 9 insertions, 1 deletions
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: |