-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Make CurrencyCollector generic over Currency (#40)
- Loading branch information
1 parent
f60b7d7
commit 17ee450
Showing
7 changed files
with
40 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,24 @@ | ||
from collections.abc import Mapping | ||
from typing import Generic | ||
from typing import TypeAlias | ||
from typing import TypeVar | ||
|
||
from immutables import Map | ||
|
||
from ._base import Currency | ||
|
||
CurrencyRegistry: TypeAlias = Mapping[str, Currency] | ||
C = TypeVar("C", bound=Currency) | ||
CurrencyRegistry: TypeAlias = Mapping[str, C] | ||
|
||
|
||
class CurrencyCollector: | ||
class CurrencyCollector(Generic[C]): | ||
__slots__ = ("__collection",) | ||
|
||
def __init__(self) -> None: | ||
self.__collection = list[tuple[str, Currency]]() | ||
self.__collection = list[tuple[str, C]]() | ||
|
||
def add(self, currency: Currency) -> None: | ||
def add(self, currency: C) -> None: | ||
self.__collection.append((currency.code, currency)) | ||
|
||
def finalize(self) -> CurrencyRegistry: | ||
def finalize(self) -> CurrencyRegistry[C]: | ||
return Map(self.__collection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters