Skip to content

Commit d6677c5

Browse files
committed
Replace runtime asserts in fileset.py
1 parent 3a76a94 commit d6677c5

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/commoncode/fileset.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ def get_matches(path, patterns, all_matches=False):
119119

120120
matches = []
121121
if not isinstance(patterns, dict):
122-
assert isinstance(patterns, (list, tuple)), "Invalid patterns: {}".format(patterns)
122+
if not isinstance(patterns, (list, tuple)):
123+
raise TypeError(f"Invalid patterns: expected dict, list or tuple, got {type(patterns)!r}")
123124
patterns = {p: p for p in patterns}
124125

126+
125127
for pat, value in patterns.items():
126128
if not pat or not pat.strip():
127129
continue
@@ -157,8 +159,11 @@ def load(location):
157159
if not location:
158160
return tuple()
159161
fn = os.path.abspath(os.path.normpath(os.path.expanduser(location)))
160-
msg = ("File %(location)s does not exist or not a file.") % locals()
161-
assert os.path.exists(fn) and os.path.isfile(fn), msg
162+
163+
if not os.path.exists(fn) or not os.path.isfile(fn):
164+
raise FileNotFoundError(f"File {location} does not exist or is not a file.")
165+
166+
162167
mode = "r"
163168
with open(fn, mode) as f:
164169
return [line.strip() for line in f if line and line.strip()]

0 commit comments

Comments
 (0)