From 8406e13e346478bc7e837f123c9e9ca85fc96b08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Kali=C5=84ski?= Date: Tue, 10 Dec 2024 15:26:01 +0100 Subject: [PATCH] Fix path name conflict --- pyproject.toml | 2 +- src/haiway/state/structure.py | 12 ------ tests/test_attribute_path.py | 80 ++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 37 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a01f9cf..fc2d979 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "haiway" description = "Framework for dependency injection and state management within structured concurrency model." -version = "0.6.3" +version = "0.6.4" readme = "README.md" maintainers = [ { name = "Kacper KaliƄski", email = "kacper.kalinski@miquido.com" }, diff --git a/src/haiway/state/structure.py b/src/haiway/state/structure.py index 62cc662..4c5ef20 100644 --- a/src/haiway/state/structure.py +++ b/src/haiway/state/structure.py @@ -181,18 +181,6 @@ def __init__( ), ) - @classmethod - def path[Attribute]( - cls, - path: Attribute, - /, - ) -> AttributePath[Self, Attribute]: - assert isinstance( # nosec: B101 - path, AttributePath - ), "Prepare parameter path by using Self._.path.to.property or explicitly" - - return cast(AttributePath[Self, Attribute], path) - def updating[Value]( self, path: AttributePath[Self, Value] | Value, diff --git a/tests/test_attribute_path.py b/tests/test_attribute_path.py index e41718d..888727a 100644 --- a/tests/test_attribute_path.py +++ b/tests/test_attribute_path.py @@ -1,4 +1,5 @@ from collections.abc import Mapping, Sequence +from typing import cast from haiway import AttributePath, State @@ -60,36 +61,49 @@ class ExampleState(State): def test_id_path_points_to_self(): - path: AttributePath[ExampleState, ExampleState] = ExampleState.path(ExampleState._) + path: AttributePath[ExampleState, ExampleState] = cast( + AttributePath[ExampleState, ExampleState], + ExampleState._, + ) assert path(state) == state assert path.__repr__() == "ExampleState" assert str(path) == "" def test_attribute_path_points_to_attribute(): - path: AttributePath[ExampleState, str] = ExampleState.path(ExampleState._.answer) + path: AttributePath[ExampleState, str] = cast( + AttributePath[ExampleState, str], + ExampleState._.answer, + ) assert path(state) == state.answer assert path.__repr__() == "ExampleState.answer" assert str(path) == "answer" def test_nested_attribute_path_points_to_nested_attribute(): - path: AttributePath[ExampleState, float] = ExampleState.path(ExampleState._.nested.value) + path: AttributePath[ExampleState, float] = cast( + AttributePath[ExampleState, float], + ExampleState._.nested.value, + ) assert path(state) == state.nested.value assert path.__repr__() == "ExampleState.nested.value" assert str(path) == "nested.value" def test_recursive_attribute_path_points_to_attribute(): - path: AttributePath[ExampleState, RecursiveState] = ExampleState.path(ExampleState._.recursive) + path: AttributePath[ExampleState, RecursiveState] = cast( + AttributePath[ExampleState, RecursiveState], + ExampleState._.recursive, + ) assert path(state) == state.recursive assert path.__repr__() == "ExampleState.recursive" assert str(path) == "recursive" def test_list_item_path_points_to_item(): - path: AttributePath[ExampleState, SequenceState] = ExampleState.path( - ExampleState._.list_models[1] + path: AttributePath[ExampleState, SequenceState] = cast( + AttributePath[ExampleState, SequenceState], + ExampleState._.list_models[1], ) assert path(state) == state.list_models[1] assert path.__repr__() == "ExampleState.list_models[1]" @@ -97,8 +111,9 @@ def test_list_item_path_points_to_item(): def test_tuple_item_path_points_to_item(): - path: AttributePath[ExampleState, SequenceState] = ExampleState.path( - ExampleState._.tuple_models[1] + path: AttributePath[ExampleState, SequenceState] = cast( + AttributePath[ExampleState, SequenceState], + ExampleState._.tuple_models[1], ) assert path(state) == state.tuple_models[1] assert path.__repr__() == "ExampleState.tuple_models[1]" @@ -106,8 +121,8 @@ def test_tuple_item_path_points_to_item(): def test_mixed_tuple_item_path_points_to_item(): - path: AttributePath[ExampleState, DictState] = ExampleState.path( - ExampleState._.tuple_mixed_models[1] + path: AttributePath[ExampleState, DictState] = cast( + AttributePath[ExampleState, DictState], ExampleState._.tuple_mixed_models[1] ) assert path(state) == state.tuple_mixed_models[1] assert path.__repr__() == "ExampleState.tuple_mixed_models[1]" @@ -115,8 +130,9 @@ def test_mixed_tuple_item_path_points_to_item(): def test_dict_item_path_points_to_item(): - path: AttributePath[ExampleState, DictState] = ExampleState.path( - ExampleState._.dict_models["B"] + path: AttributePath[ExampleState, DictState] = cast( + AttributePath[ExampleState, DictState], + ExampleState._.dict_models["B"], ) assert path(state) == state.dict_models["B"] assert path.__repr__() == "ExampleState.dict_models[B]" @@ -124,14 +140,20 @@ def test_dict_item_path_points_to_item(): def test_id_path_set_updates_self(): - path: AttributePath[ExampleState, ExampleState] = ExampleState.path(ExampleState._) + path: AttributePath[ExampleState, ExampleState] = cast( + AttributePath[ExampleState, ExampleState], + ExampleState._, + ) assert path(state, updated=state) == state assert path.__repr__() == "ExampleState" assert str(path) == "" def test_attribute_path_set_updates_attribute(): - path: AttributePath[ExampleState, str] = ExampleState.path(ExampleState._.answer) + path: AttributePath[ExampleState, str] = cast( + AttributePath[ExampleState, str], + ExampleState._.answer, + ) updated: ExampleState = path(state, updated="changed") assert updated != state assert updated.answer == "changed" @@ -141,7 +163,10 @@ def test_attribute_path_set_updates_attribute(): def test_nested_attribute_path_set_updates_nested_attribute(): - path: AttributePath[ExampleState, float] = ExampleState.path(ExampleState._.nested.value) + path: AttributePath[ExampleState, float] = cast( + AttributePath[ExampleState, float], + ExampleState._.nested.value, + ) updated: ExampleState = path(state, updated=11.0) assert updated != state assert updated.nested.value == 11 @@ -151,7 +176,10 @@ def test_nested_attribute_path_set_updates_nested_attribute(): def test_recursive_attribute_set_updates_attribute(): - path: AttributePath[ExampleState, RecursiveState] = ExampleState.path(ExampleState._.recursive) + path: AttributePath[ExampleState, RecursiveState] = cast( + AttributePath[ExampleState, RecursiveState], + ExampleState._.recursive, + ) updated: ExampleState = path(state, updated=RecursiveState(more=None)) assert updated != state assert updated.recursive == RecursiveState(more=None) @@ -163,8 +191,9 @@ def test_recursive_attribute_set_updates_attribute(): def test_list_item_path_set_updates_item(): - path: AttributePath[ExampleState, SequenceState] = ExampleState.path( - ExampleState._.list_models[1] + path: AttributePath[ExampleState, SequenceState] = cast( + AttributePath[ExampleState, SequenceState], + ExampleState._.list_models[1], ) updated: ExampleState = path(state, updated=SequenceState(value=11)) assert updated != state @@ -177,8 +206,9 @@ def test_list_item_path_set_updates_item(): def test_tuple_item_path_set_updates_item(): - path: AttributePath[ExampleState, SequenceState] = ExampleState.path( - ExampleState._.tuple_models[1] + path: AttributePath[ExampleState, SequenceState] = cast( + AttributePath[ExampleState, SequenceState], + ExampleState._.tuple_models[1], ) updated: ExampleState = path(state, updated=SequenceState(value=11)) assert updated != state @@ -191,8 +221,9 @@ def test_tuple_item_path_set_updates_item(): def test_mixed_tuple_item_set_updates_item(): - path: AttributePath[ExampleState, DictState] = ExampleState.path( - ExampleState._.tuple_mixed_models[1] + path: AttributePath[ExampleState, DictState] = cast( + AttributePath[ExampleState, DictState], + ExampleState._.tuple_mixed_models[1], ) updated: ExampleState = path(state, updated=DictState(key="updated")) assert updated != state @@ -205,8 +236,9 @@ def test_mixed_tuple_item_set_updates_item(): def test_dict_item_path_set_updates_item(): - path: AttributePath[ExampleState, DictState] = ExampleState.path( - ExampleState._.dict_models["B"] + path: AttributePath[ExampleState, DictState] = cast( + AttributePath[ExampleState, DictState], + ExampleState._.dict_models["B"], ) updated: ExampleState = path(state, updated=DictState(key="updated")) assert updated != state