Skip to content

Commit a917ea9

Browse files
yt-msMidnighter
authored andcommitted
style: more PR feedback
1 parent 7e02750 commit a917ea9

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/structurizr/model/container.py

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

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

src/structurizr/model/model.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ def __contains__(self, element: Element):
118118
@property
119119
def software_systems(self) -> Set[SoftwareSystem]:
120120
"""Return the software systems in the model."""
121-
return set([e for e in self.get_elements() if isinstance(e, SoftwareSystem)])
121+
return {e for e in self.get_elements() if isinstance(e, SoftwareSystem)}
122122

123123
@property
124124
def people(self) -> Set[Person]:
125125
"""Return the people in the model."""
126-
return set([e for e in self.get_elements() if isinstance(e, Person)])
126+
return {e for e in self.get_elements() if isinstance(e, Person)}
127127

128128
@classmethod
129129
def hydrate(cls, model_io: ModelIO) -> "Model":
@@ -199,6 +199,11 @@ 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):
202207
"""Add a newly constructed element to the model."""
203208
if isinstance(element, Person):
204209
if any(element.name == p.name for p in self.people):
@@ -218,7 +223,6 @@ def __iadd__(self, element: Element) -> "Model":
218223
f"you have added it to the parent element."
219224
)
220225
self._add_element(element)
221-
return self
222226

223227
def add_container_instance(
224228
self,

src/structurizr/model/software_system.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SoftwareSystem(StaticStructureElement):
6363
"""
6464

6565
def __init__(self, *, location: Location = Location.Unspecified, **kwargs) -> None:
66-
""""""
66+
"""Initialise a new SoftwareSystem."""
6767
super().__init__(**kwargs)
6868
self.location = location
6969
self.containers: Set[Container] = set()
@@ -85,10 +85,10 @@ def add_container(
8585
return container
8686

8787
def __iadd__(self, container: Container) -> "SoftwareSystem":
88-
"""Add a newly constructed container to this system and register with its model."""
89-
# TODO: once we move past python 3.6 change to proper return type via __future__.annotations
88+
"""Add a new container to this system and register with its model."""
89+
# TODO: once we move past python 3.6 change to proper return type via
90+
# __future__.annotations
9091
if container in self.containers:
91-
# Nothing to do
9292
return self
9393

9494
if self.get_container_with_name(container.name):
@@ -104,8 +104,7 @@ def __iadd__(self, container: Container) -> "SoftwareSystem":
104104
f"{container.parent}. Cannot add to {self}."
105105
)
106106
self.containers.add(container)
107-
model = self.get_model()
108-
model += container
107+
self.model.add(container)
109108
return self
110109

111110
def get_container_with_name(self, name: str) -> Container:
@@ -116,7 +115,7 @@ def get_container_with_name(self, name: str) -> Container:
116115
def hydrate(
117116
cls, software_system_io: SoftwareSystemIO, model: "Model"
118117
) -> "SoftwareSystem":
119-
""""""
118+
"""Create a new SoftwareSystem instance and hydrate it from its IO."""
120119
software_system = cls(
121120
**cls.hydrate_arguments(software_system_io),
122121
location=software_system_io.location,

tests/unit/model/test_container.py

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

30-
def __iadd__(self, component):
30+
def add(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
3635

3736

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

tests/unit/model/test_software_system.py

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

33-
def __iadd__(self, container):
33+
def add(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
3938

4039

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

0 commit comments

Comments
 (0)