Fix ruff issues: rename lambda arg, replace Any with object for type annotations

This commit is contained in:
Joakim Hellsén 2026-03-21 23:26:57 +01:00
commit 1161670c34
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
9 changed files with 275 additions and 137 deletions

37
core/utils.py Normal file
View file

@ -0,0 +1,37 @@
from typing import Any
from xml.etree.ElementTree import Element # noqa: S405
from xml.etree.ElementTree import SubElement # noqa: S405
from xml.etree.ElementTree import tostring # noqa: S405
from django.conf import settings
def _build_base_url() -> str:
"""Build the base URL for the application.
Returns:
str: The base URL as configured in settings.BASE_URL.
"""
return settings.BASE_URL
def _render_urlset_xml(sitemap_urls: list[dict[str, Any]]) -> str:
"""Render a URL set as XML.
Args:
sitemap_urls: List of sitemap URL entry dictionaries.
Returns:
str: Serialized XML for a <urlset> containing the provided URLs.
"""
urlset = Element("urlset")
urlset.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
for url_entry in sitemap_urls:
url = SubElement(urlset, "url")
loc = url_entry.get("loc")
if loc:
child = SubElement(url, "loc")
child.text = loc
return tostring(urlset, encoding="unicode")