changeset 376:54a6d4534ef4

Convert some further value checks from plain Python assertions into real checks
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 05 May 2025 13:04:49 +0200
parents 7044c2900890
children 6b327893a9c3
files cutils/util/__init__.py cutils/util/fnmatch.py
diffstat 2 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/cutils/util/__init__.py	Mon May 05 09:21:55 2025 +0200
+++ b/cutils/util/__init__.py	Mon May 05 13:04:49 2025 +0200
@@ -393,12 +393,17 @@
     tformatstr = formatstr.decode("latin1")
     tvalues = []
     for v in values:
+        # Do not automatically convert text (unicode) string values into bytes.
         if PY2:
             if isinstance(v, unicode):  # noqa: F821  undefined name 'unicode'
-                assert False
+                raise TypeError(
+                    "unicode values not supported when interpolating"
+                    " into bytes")
         else:
             if isinstance(v, str):
-                assert False
+                raise TypeError(
+                    "unicode (native string) values not supported when"
+                    " interpolating into bytes")
         if isinstance(v, bytes):
             tvalues.append(v.decode("latin1"))
         else:
--- a/cutils/util/fnmatch.py	Mon May 05 09:21:55 2025 +0200
+++ b/cutils/util/fnmatch.py	Mon May 05 13:04:49 2025 +0200
@@ -213,7 +213,10 @@
         matchers = []
         if filter_definitions:
             for action, kpattern in filter_definitions:
-                assert action in ("include", "exclude", "accept-treesum")
+                if action not in ("include", "exclude", "accept-treesum"):
+                    raise ValueError(
+                        "unknown action in filter definitions: {}"
+                        .format(action))
                 kind, sep, pattern = kpattern.partition(':')
                 if not sep:
                     # use the default