Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion unstructured/partition/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def exactly_one(**kwargs: Any) -> None:
Example:
>>> exactly_one(filename=filename, file=file, text=text, url=url)
"""
if sum([(arg is not None and arg != "") for arg in kwargs.values()]) != 1:
# Use generator expression to avoid creating a temporary list, reducing memory use
if sum((arg is not None and arg != "") for arg in kwargs.values()) != 1:
names = list(kwargs.keys())
if len(names) > 1:
message = f"Exactly one of {', '.join(names[:-1])} and {names[-1]} must be specified."
Expand Down
14 changes: 2 additions & 12 deletions unstructured/staging/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,21 +462,11 @@ def filter_element_types(
include_element_types=include_element_types,
exclude_element_types=exclude_element_types,
)

filtered_elements: list[Element] = []
if include_element_types:
for element in elements:
if type(element) in include_element_types:
filtered_elements.append(element)

return filtered_elements
return [element for element in elements if type(element) in include_element_types]

elif exclude_element_types:
for element in elements:
if type(element) not in exclude_element_types:
filtered_elements.append(element)

return filtered_elements
return [element for element in elements if type(element) not in exclude_element_types]

return list(elements)

Expand Down