Skip to content

Commit 4d115a3

Browse files
yt-msMidnighter
authored andcommitted
refactor: revert changes to Model.__iadd__
1 parent 128b62e commit 4d115a3

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

src/structurizr/model/container.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def __iadd__(self, component: Component) -> "Container":
154154
f"{component.parent}. Cannot add to {self}."
155155
)
156156
self._components.add(component)
157-
self.model.add(component)
157+
model = self.model
158+
model += component
158159
return self
159160

160161
def get_component_with_name(self, name: str) -> Component:

src/structurizr/model/model.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,6 @@ def add_software_system(self, **kwargs) -> SoftwareSystem:
199199
return software_system
200200

201201
def __iadd__(self, element: Element) -> "Model":
202-
"""Add a newly constructed element to the model."""
203-
self.add(element)
204-
return self
205-
206-
def add(self, element: Element):
207202
"""Add a newly constructed element to the model."""
208203
if isinstance(element, Person):
209204
if any(element.name == p.name for p in self.people):
@@ -223,6 +218,7 @@ def add(self, element: Element):
223218
f"you have added it to the parent element."
224219
)
225220
self._add_element(element)
221+
return self
226222

227223
def add_container_instance(
228224
self,

src/structurizr/model/software_system.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def __iadd__(self, container: Container) -> "SoftwareSystem":
109109
f"{container.parent}. Cannot add to {self}."
110110
)
111111
self._containers.add(container)
112-
self.model.add(container)
112+
model = self.model
113+
model += container
113114
return self
114115

115116
def get_container_with_name(self, name: str) -> Container:

tests/unit/model/test_container.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ def __init__(self):
2727
self.empty_container = Container(name="Container", description="Description")
2828
self.empty_container.set_model(self)
2929

30-
def add(self, component):
30+
def __iadd__(self, component):
3131
"""Simulate the model assigning IDs to new elements."""
3232
if not component.id:
3333
component.id = "id"
3434
component.set_model(self)
35+
return self
3536

3637

3738
@pytest.fixture(scope="function")

tests/unit/model/test_software_system.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ def __init__(self):
3030
self.empty_system = SoftwareSystem(name="Sys")
3131
self.empty_system.set_model(self)
3232

33-
def add(self, container):
33+
def __iadd__(self, container):
3434
"""Simulate the model assigning IDs to new elements."""
3535
if not container.id:
3636
container.id = "id"
3737
container.set_model(self)
38+
return self
3839

3940

4041
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)