Skip to content

Commit

Permalink
Improve assignment of sections and tags
Browse files Browse the repository at this point in the history
This allows to assign an existing instance, which comes handy for
example when assigning a sliced Section.

Signed-off-by: Nikola Forró <nforro@redhat.com>
  • Loading branch information
nforro committed May 13, 2022
1 parent 2faf042 commit ca7fd22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion specfile/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ def __setattr__(self, name: str, value: List[str]) -> None:
if name.split()[0].lower() not in SECTION_NAMES:
return super().__setattr__(name, value)
try:
self.data[self.find(name)].data = value
if isinstance(value, Section):
self.data[self.find(name)] = value
else:
self.data[self.find(name)].data = value
except ValueError:
raise AttributeError(name)

Expand Down
5 changes: 4 additions & 1 deletion specfile/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,10 @@ def __setattr__(self, name: str, value: str) -> None:
if name.capitalize().rstrip("0123456789") not in TAG_NAMES:
return super().__setattr__(name, value)
try:
self.data[self.find(name)].value = value
if isinstance(value, Tag):
self.data[self.find(name)] = value
else:
self.data[self.find(name)].value = value
except ValueError:
raise AttributeError(name)

Expand Down

0 comments on commit ca7fd22

Please sign in to comment.