Simplify unnecessary re.findall calls (#147907)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Ville Skyttä 2025-07-04 21:26:36 +00:00 committed by GitHub
parent ca85ffc068
commit dcad5bbe04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 10 deletions

View File

@ -65,12 +65,10 @@ def download_file(service: ServiceCall) -> None:
else: else:
if filename is None and "content-disposition" in req.headers: if filename is None and "content-disposition" in req.headers:
match = re.findall( if match := re.search(
r"filename=(\S+)", req.headers["content-disposition"] r"filename=(\S+)", req.headers["content-disposition"]
) ):
filename = match.group(1).strip("'\" ")
if match:
filename = match[0].strip("'\" ")
if not filename: if not filename:
filename = os.path.basename(url).strip() filename = os.path.basename(url).strip()

View File

@ -48,11 +48,8 @@ def add_new_outputs(
def format_ref_id(ref_id: str) -> str | None: def format_ref_id(ref_id: str) -> str | None:
"""Format the Qbus ref_id.""" """Format the Qbus ref_id."""
matches: list[str] = re.findall(_REFID_REGEX, ref_id) if match := _REFID_REGEX.search(ref_id):
return match.group(1).replace("/", "-")
if len(matches) > 0:
if ref_id := matches[0]:
return ref_id.replace("/", "-")
return None return None