[Git][security-tracker-team/security-tracker][helmutg/type-improvements] 5 commits: security_db.py: rewrite mergeLists using sets

Helmut Grohne (@helmutg) helmutg at debian.org
Thu Aug 6 17:31:35 BST 2026



Helmut Grohne pushed to branch helmutg/type-improvements at Debian Security Tracker / security-tracker


Commits:
b5eadf0e by Helmut Grohne at 2026-08-06T13:51:01+02:00
security_db.py: rewrite mergeLists using sets

Aside from being faster, this avoids changing the type of the result
variable.

- - - - -
0939b1ed by Helmut Grohne at 2026-08-06T13:51:01+02:00
python: avoid more variable type changes

If we ever want to head into type checking, the type of value stored in
a variable should not change. Thus rename affected assignments or elide
them entirely.

- - - - -
d7561029 by Helmut Grohne at 2026-08-06T13:51:01+02:00
tracker_service.py: narrow implied type of filters attribute

The lookup in params may return None in principle. This influences type
deduction and filters is assumed to be able to hold None, but the next
line changes that. In combining them, the deduced type of filters
becomes narrower.

- - - - -
ddb4419d by Helmut Grohne at 2026-08-06T13:51:01+02:00
tracker_service.py: don't pass None via body_attribs

While a None value might be acceptable there, it is discarded anyway.
Rather than supporting that use case, simply avoid passing it.

- - - - -
0d152b45 by Helmut Grohne at 2026-08-06T13:51:01+02:00
tracker_service.py: explicitly cast hide_check to bool

When we pass it to getTODOs a real bool is expected, so convert the
thing that might be a list early.

- - - - -


2 changed files:

- bin/tracker_service.py
- lib/python/security_db.py


Changes:

=====================================
bin/tracker_service.py
=====================================
@@ -45,9 +45,9 @@ class BugFilter:
         self.params = {}
         for (prop, desc, field) in self.action_list:
             self.params[prop] = int(params.get(prop, (0,))[0])
-        self.filters=params.get('filter')
-        if not self.filters:
-            self.filters=['high_urgency', 'medium_urgency', 'low_urgency', 'unassigned_urgency']
+        self.filters = (
+            params.get('filter') or ['high_urgency', 'medium_urgency', 'low_urgency', 'unassigned_urgency']
+        )
 
     def actions(self, url):
         """Returns a HTML snippet which can be used to change the filter."""
@@ -925,7 +925,7 @@ checker to find out why they have not entered testing yet."""),
                                  "Remote", ""))])
 
     def page_status_todo(self, path, params, url):
-        hide_check = params.get('hide_check', False)
+        hide_check = bool(params.get('hide_check', False))
         if hide_check:
             flags = A(url.updateParamsDict({'hide_check' : None}),
                       'Show "check" TODOs')
@@ -1177,13 +1177,9 @@ not unimportant."""),
         def gen():
             for (rel, subrel, archive, sources, archs) \
                     in self.db.availableReleases():
-                if sources:
-                    sources = 'yes'
-                else:
-                    sources = 'no'
                 if 'source' in archs:
                     archs.remove('source')
-                yield rel, subrel, archive, sources, make_list(archs)
+                yield rel, subrel, archive, "yes" if sources else "no" , make_list(archs)
         return self.create_page(
             url, "Available releases",
             [P("""The security issue database is checked against
@@ -1289,17 +1285,16 @@ Debian bug number.'''),
                              "Source"),
                     " ", A(url.absolute("https://salsa.debian.org/security-tracker-team/security-tracker"), "(Git)"),
                     )))
+        body_attribs = {}
         if search_in_page:
-            on_load = "selectSearch()"
-        else:
-            on_load = None
+            body_attribs["onload"] = "selectSearch()"
         head_contents = compose(
             LINK(' ', href=url.scriptRelative("style.css")),
             SCRIPT(' ', src=url.scriptRelative("script.js")),
         ).toHTML()
         return HTMLResult(self.add_title(title, body,
                                          head_contents=head_contents,
-                                         body_attribs={'onload': on_load}),
+                                         body_attribs=body_attribs),
                           doctype=self.html_dtd(),
                           status=status)
 


=====================================
lib/python/security_db.py
=====================================
@@ -73,14 +73,7 @@ def mergeLists(a, b):
             b = []
         else:
             b = b.split(',')
-    result = {}
-    for x in a:
-        result[x] = 1
-    for x in b:
-        result[x] = 1
-    result = list(result.keys())
-    result.sort()
-    return result
+    return sorted(set(a).union(b))
 
 class NVDEntry:
     """A class for an entry in the nvd_data table.
@@ -155,7 +148,7 @@ def getBugsForSourcePackage(cursor, pkg):
 
     # Restrict to regular releases excluding e.g. backports.
     release_names = tuple(debian_support.Release.releases)
-    data = itertools.starmap(
+    data_iter = itertools.starmap(
         BugsForSourcePackage_internal,
         cursor.execute(
             BugsForSourcePackage_query.replace(
@@ -168,7 +161,7 @@ def getBugsForSourcePackage(cursor, pkg):
     all_bugs = []
     version_key = functools.cmp_to_key(version_compare)
     # Group by bug name.
-    for bug_name, data in itertools.groupby(data,
+    for bug_name, data in itertools.groupby(data_iter,
                                             lambda row: row.bug_name):
         description = None
         open_seen = False
@@ -1649,9 +1642,9 @@ class DB:
                              kind, urgency_to_flag[urgency], remote,
                              fix_available,
                              package, fixed_version, description))
-        result = zlib.compress(''.join(result).encode('utf-8'), 9)
+        compressed = zlib.compress(''.join(result).encode('utf-8'), 9)
 
-        self.storeExport('debsecan/release/' + release, 'application/octet-stream', result)
+        self.storeExport('debsecan/release/' + release, 'application/octet-stream', compressed)
 
         c.execute("DROP TABLE vulnlist")
 
@@ -1814,8 +1807,8 @@ class DB:
         fill_vuln_list()
 
         def store_value(name, value):
-            value = zlib.compress(value.encode('utf-8'), 9)
-            self.storeExport('debsecan/' + name, 'application/octet-stream', value)
+            compressed = zlib.compress(value.encode('utf-8'), 9)
+            self.storeExport('debsecan/' + name, 'application/octet-stream', compressed)
 
         def gen_release(release):
             result = result_start[:]
@@ -1847,7 +1840,7 @@ class DB:
             gen_release(release)
 
         result = result_start
-        for (prefix, release, suffix) in vuln_list:
+        for (prefix, releases, suffix) in vuln_list:
             result.append(prefix + ' ' + suffix)
         result.append('')
         result.append('')
@@ -2107,8 +2100,8 @@ class DB:
         RELEASE-LIST, VERSION, VULNERABLE-FLAG) of source packages
         which are related to the given bug."""
 
-        releases = config.get_supported_releases()
-        values = [bug] + releases
+        supported_releases = config.get_supported_releases()
+        values = [bug] + supported_releases
 
         for (package, releases, version, vulnerable) in cursor.execute(
             """SELECT package, string_list(release), version, vulnerable
@@ -2117,7 +2110,7 @@ class DB:
             p.version AS version, s.vulnerable AS vulnerable
             FROM source_package_status AS s, source_packages AS p
             WHERE s.bug_name = ? AND p.rowid = s.package
-            AND release in (""" + ",".join("?" * len(releases)) + """))
+            AND release in (""" + ",".join("?" * len(supported_releases)) + """))
             GROUP BY package, version, vulnerable
             ORDER BY package, releasepart_to_number(release), subreleasepart_to_number(release), version COLLATE version""",
             values):



View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/-/compare/b8f08ba5f10aef1461adcb8f71a5231f78dad818...0d152b4570d769ef383cc21ea2c813b6fbd99e57

-- 
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/-/compare/b8f08ba5f10aef1461adcb8f71a5231f78dad818...0d152b4570d769ef383cc21ea2c813b6fbd99e57
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-security-tracker-commits/attachments/20260806/b349b445/attachment-0001.htm>


More information about the debian-security-tracker-commits mailing list