From 3c068f44d4234e1d13342e36584fafdab5f33b7d Mon Sep 17 00:00:00 2001 From: Vladimir Prusakov Date: Sat, 4 Nov 2023 12:40:43 +0200 Subject: [PATCH] 0.1.13 (2023-11-04) ------------------- * [fix] vlist.replace() --- CHANGELOG.rst | 2 +- README.rst | 12 ++++++------ examples/vlist_.py | 2 +- pyproject.toml | 4 ++-- tests/test_vlist.py | 6 +++--- vhelpers/vlist.py | 14 +++++++------- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d0fdf08..7e5cb3f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,7 +4,7 @@ CHANGELOG ========= -0.1.12 (2023-11-04) +0.1.13 (2023-11-04) ------------------- * [new] vlist.replace() diff --git a/README.rst b/README.rst index 9e639af..4eba0d6 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ or install the package from github.com release .. code:: bash - pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.12.tar.gz + pip install https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.13.tar.gz or install the package from github.com repository @@ -288,16 +288,16 @@ Return assert vlist.no_dupl(items=[1, 2, 1]) == [1, 2] -replace(items, item, other) ---------------------------- +replace(items, old, new) +------------------------ Replace one item with another. =========== ====== =================================================================================== Parameter Type Description =========== ====== =================================================================================== items *list* The list of items where need replace item. -item *Any* The item to be replaced. -other *Any* The item to replace with. +old *Any* The item to be replaced. +new *Any* The item to replace with. =========== ====== =================================================================================== Return @@ -307,7 +307,7 @@ Return from vhelpers import vlist - assert vlist.replace(items=[1, 2, 3], item=2, other=4) == [1, 4, 3] + assert vlist.replace(items=[1, 2, 3], old=2, new=4) == [1, 4, 3] split(text, chars, ignore) diff --git a/examples/vlist_.py b/examples/vlist_.py index 93cc7c7..ca2e2b6 100644 --- a/examples/vlist_.py +++ b/examples/vlist_.py @@ -12,7 +12,7 @@ assert vlist.no_dupl(items=[1, 2, 1]) == [1, 2] # Replace one item with another. -assert vlist.replace(items=[1, 2, 3], item=2, other=4) == [1, 4, 3] +assert vlist.replace(items=[1, 2, 3], old=2, new=4) == [1, 4, 3] # Split string by punctuation chars. assert vlist.split(text="1; 2_3-4X5,6", chars="_X", ignore=",") == ["1", "2", "3", "4", "5,6"] diff --git a/pyproject.toml b/pyproject.toml index 408a0a9..67a65cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "vhelpers" -version = "0.1.12" +version = "0.1.13" description = "Often used functions in vladimirs-git projects" authors = ["Vladimir Prusakov "] readme = "README.rst" @@ -41,7 +41,7 @@ test = ["pytest"] [tool.poetry.urls] "Bug Tracker" = "https://github.com/vladimirs-git/vhelpers/issues" -"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.12.tar.gz" +"Download URL" = "https://github.com/vladimirs-git/vhelpers/archive/refs/tags/0.1.13.tar.gz" [build-system] diff --git a/tests/test_vlist.py b/tests/test_vlist.py index fb7eaf9..099a424 100644 --- a/tests/test_vlist.py +++ b/tests/test_vlist.py @@ -58,7 +58,7 @@ def test__no_dupl(items, expected): assert actual == expected -@pytest.mark.parametrize("items, item, other, expected", [ +@pytest.mark.parametrize("items, old, new, expected", [ ([], None, None, []), ([1], None, None, [1]), ([None], None, None, [None]), @@ -66,9 +66,9 @@ def test__no_dupl(items, expected): ([1, 2, 3], 2, 4, [1, 4, 3]), ([1, {2: 2}, 3], {2: 2}, 4, [1, 4, 3]), ]) -def test__replace(items: list, item: Any, other: Any, expected: list): +def test__replace(items: list, old: Any, new: Any, expected: list): """vlist.replace().""" - vlist.replace(items=items, item=item, other=other) + vlist.replace(items=items, old=old, new=new) assert items == expected diff --git a/vhelpers/vlist.py b/vhelpers/vlist.py index f0b6d64..9bee28b 100644 --- a/vhelpers/vlist.py +++ b/vhelpers/vlist.py @@ -90,19 +90,19 @@ def no_dupl(items: SeqTy) -> ListTy: return items_ -def replace(items: list, item: Any, other: Any) -> None: +def replace(items: list, old: Any, new: Any) -> None: """Replace one item with another. :param items: The list of items where need replace item. - :param item: The item to be replaced. - :param other: The item to replace with. + :param old: The item to be replaced. + :param new: The item to replace with. :return: None. Update items. :example: - replace(items=[1, 2, 3], item=2, other=4) -> [1, 4, 3] + replace(items=[1, 2, 3], old=2, new=4) -> [1, 4, 3] """ - if item in items: - idx = items.index(item) - items[idx] = other + if old in items: + idx = items.index(old) + items[idx] = new def split(text: str, chars: str = "", ignore: str = "") -> LStr: