Skip to content

Commit ca7fd22

Browse files
committed
Improve assignment of sections and tags
This allows to assign an existing instance, which comes handy for example when assigning a sliced Section. Signed-off-by: Nikola Forró <[email protected]>
1 parent 2faf042 commit ca7fd22

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

specfile/sections.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@ def __setattr__(self, name: str, value: List[str]) -> None:
143143
if name.split()[0].lower() not in SECTION_NAMES:
144144
return super().__setattr__(name, value)
145145
try:
146-
self.data[self.find(name)].data = value
146+
if isinstance(value, Section):
147+
self.data[self.find(name)] = value
148+
else:
149+
self.data[self.find(name)].data = value
147150
except ValueError:
148151
raise AttributeError(name)
149152

specfile/tags.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,10 @@ def __setattr__(self, name: str, value: str) -> None:
577577
if name.capitalize().rstrip("0123456789") not in TAG_NAMES:
578578
return super().__setattr__(name, value)
579579
try:
580-
self.data[self.find(name)].value = value
580+
if isinstance(value, Tag):
581+
self.data[self.find(name)] = value
582+
else:
583+
self.data[self.find(name)].value = value
581584
except ValueError:
582585
raise AttributeError(name)
583586

0 commit comments

Comments
 (0)