Skip to content

Commit

Permalink
update: locale_str.joinでextrasを渡せるように引数を追加。
Browse files Browse the repository at this point in the history
  • Loading branch information
tasuren committed Feb 21, 2023
1 parent 0479408 commit c50b6f2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "i21y"
version = "0.1.0.post1"
version = "0.1.1"
description = "The library for i18n support."
authors = ["Takagi Tasuku <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/i21y/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"tasuren - i21y"

__author__ = "Takagi Tasuku"
__version__ = "0.1.0.post1"
__version__ = "0.1.1"
__all__ = ("Translator", "I21YError", "TranslationNotFound", "locale_str")

from .translator import Translator
Expand Down
12 changes: 7 additions & 5 deletions src/i21y/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,26 @@ def join_raw(self, *other: str | locale_str) -> str:
@overload
def join(
self: ..., *other: str | locale_str,
cls: type[AdtnlClsT] = None
cls: type[AdtnlClsT] = None, **extras: Any
) -> AdtnlClsT: ...
@overload
def join(
self: SelfT, *other: str | locale_str,
cls: None = None
cls: None = None, **extras: Any
) -> SelfT: ...
def join(
self: SelfT, *other: str | locale_str,
cls: type[AdtnlClsT] | None = None
cls: type[AdtnlClsT] | None = None, **extras: Any
) -> SelfT | AdtnlClsT:
"""A version of :meth:`locale_str.join_raw` that returns the instance of the class that self.
Args:
*other: Target strings."""
*other: Target strings.
cls: The :class:`.locale_str` used to create the instance.
**extras: The value to pass to the ``extras`` argument of the constructor of :class:`.locale_str`."""
cls = cls or self.__class__ # type: ignore
assert cls is not None
return cls(self.join_raw(*other))
return cls(self.join_raw(*other), **extras)

def __truediv__(self: SelfT, other: LocaleStr | Iterable[LocaleStr]) -> SelfT:
if isinstance(other, str | locale_str):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_locale_str.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
assert str(LEFT) == str(RIGHT)
assert LEFT.test == RIGHT.test

assert BASE // "kakikukeko" == "aiueo.kakikukeko"
assert BASE // "kakikukeko" == "aiueo.kakikukeko"

assert BASE.join("test", a="b").extras["a"] == "b"

0 comments on commit c50b6f2

Please sign in to comment.