Skip to content

Commit

Permalink
chore: Avoid unnecessary assignment before for-loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Sep 28, 2024
1 parent 69a2afb commit 8a367dd
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions backend/exporter/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def get_tags(self) -> etree._Element:

# replaces all occurrences of full_tag with string value in the content
def set_text(self, value: str, full_tag: str) -> None:
nodes = self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag))
for node in nodes:
for node in self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag)):
if node.text:
node.text = node.text.replace(full_tag, str(value))
for child in node:
Expand All @@ -63,8 +62,7 @@ def set_element(self, element: etree._Element, full_tag: str) -> None:
)
wrapper_element.append(copy.deepcopy(element))

nodes = self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag))
for node in nodes:
for node in self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag)):
if node.text:
node.text = node.text.replace(full_tag, "")
for child in node:
Expand All @@ -85,8 +83,7 @@ def set_element(self, element: etree._Element, full_tag: str) -> None:
# does not wrap each of the new elements in <text:p>
# if the node containing full_tag is not a <text:p> element the new element is added to the root of the document
def set_elements(self, elements: list[etree._Element], full_tag: str) -> None:
nodes = self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag))
for node in nodes:
for node in self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag)):
if node.text:
node.text = node.text.replace(full_tag, "")
for child in node:
Expand Down Expand Up @@ -147,8 +144,7 @@ def merge(self, other: etree._Element, full_tag: str) -> None:
if re.match(r"\{[^}]*\}style-name", attrib_name) and child.get(attrib_name) not in DEFAULT_STYLES:
child.set(attrib_name, prefix + child.get(attrib_name))

nodes = self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag))
for node in nodes:
for node in self.content.xpath(FULL_TAG_LOCATION_XPATH.format(full_tag=full_tag)):
if node.text:
node.text = node.text.replace(full_tag, "")
for child in node:
Expand Down

0 comments on commit 8a367dd

Please sign in to comment.