Skip to content

Commit da0ee5e

Browse files
refactor asset collection to consistently use frozenset (#122)
1 parent d0805a8 commit da0ee5e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/django_bird/components.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ def get_component(self, name: str) -> Component:
117117
self._components[name] = component
118118
return component
119119

120-
def get_assets(self, asset_type: AssetType) -> list[Asset]:
121-
assets: list[Asset] = []
120+
def get_assets(self, asset_type: AssetType) -> frozenset[Asset]:
121+
assets: set[Asset] = set()
122122
for component in self._components.values():
123-
assets.extend(a for a in component.assets if a.type == asset_type)
124-
return assets
123+
for asset in component.assets:
124+
if asset.type == asset_type:
125+
assets.add(asset)
126+
return frozenset(assets)
125127

126128

127129
components = ComponentRegistry()

src/django_bird/templatetags/tags/asset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ def render(self, context: Context) -> str:
3636
assets = components.get_assets(self.asset_type)
3737
if not assets:
3838
return ""
39-
rendered = {asset.render() for asset in sorted(assets, key=lambda a: a.path)}
39+
rendered = frozenset(
40+
asset.render() for asset in sorted(assets, key=lambda a: a.path)
41+
)
4042
return "\n".join(rendered)

0 commit comments

Comments
 (0)