Skip to content

Commit 1bb6d9b

Browse files
committed
Do not use an assert for remove_tags parameter checking
1 parent 49a3e5b commit 1bb6d9b

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

.bandit.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
skips:
2-
- B101
32
- B107

w3lib/html.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,13 @@ def remove_tags(text, which_ones=(), keep=(), encoding=None):
174174
You can't remove some and keep some:
175175
176176
>>> w3lib.html.remove_tags(doc, which_ones=('a',), keep=('p',))
177-
Traceback (most recent call last):
178-
File "<stdin>", line 1, in <module>
179-
File "/usr/local/lib/python2.7/dist-packages/w3lib/html.py", line 101, in remove_tags
180-
assert not (which_ones and keep), 'which_ones and keep can not be given at the same time'
181-
AssertionError: which_ones and keep can not be given at the same time
177+
...
178+
ValueError: Cannot use both which_ones and keep
182179
>>>
183180
184181
"""
185-
186-
assert not (which_ones and keep), 'which_ones and keep can not be given at the same time'
182+
if which_ones and keep:
183+
raise ValueError('Cannot use both which_ones and keep')
187184

188185
which_ones = {tag.lower() for tag in which_ones}
189186
keep = {tag.lower() for tag in keep}

0 commit comments

Comments
 (0)