@@ -139,14 +139,18 @@ def filterwarnings(action, message="", category=Warning, module="", lineno=0,
139
139
'lineno' -- an integer line number, 0 matches all warnings
140
140
'append' -- if true, append to the list of filters
141
141
"""
142
- assert action in ("error" , "ignore" , "always" , "default" , "module" ,
143
- "once" ), "invalid action: %r" % (action ,)
144
- assert isinstance (message , str ), "message must be a string"
145
- assert isinstance (category , type ), "category must be a class"
146
- assert issubclass (category , Warning ), "category must be a Warning subclass"
147
- assert isinstance (module , str ), "module must be a string"
148
- assert isinstance (lineno , int ) and lineno >= 0 , \
149
- "lineno must be an int >= 0"
142
+ if action not in {"error" , "ignore" , "always" , "default" , "module" , "once" }:
143
+ raise ValueError (f"invalid action: { action !r} " )
144
+ if not isinstance (message , str ):
145
+ raise TypeError ("message must be a string" )
146
+ if not isinstance (category , type ) or not issubclass (category , Warning ):
147
+ raise TypeError ("category must be a Warning subclass" )
148
+ if not isinstance (module , str ):
149
+ raise TypeError ("module must be a string" )
150
+ if not isinstance (lineno , int ):
151
+ raise TypeError ("lineno must be an int" )
152
+ if lineno < 0 :
153
+ raise ValueError ("lineno must be an int >= 0" )
150
154
151
155
if message or module :
152
156
import re
@@ -172,10 +176,12 @@ def simplefilter(action, category=Warning, lineno=0, append=False):
172
176
'lineno' -- an integer line number, 0 matches all warnings
173
177
'append' -- if true, append to the list of filters
174
178
"""
175
- assert action in ("error" , "ignore" , "always" , "default" , "module" ,
176
- "once" ), "invalid action: %r" % (action ,)
177
- assert isinstance (lineno , int ) and lineno >= 0 , \
178
- "lineno must be an int >= 0"
179
+ if action not in {"error" , "ignore" , "always" , "default" , "module" , "once" }:
180
+ raise ValueError (f"invalid action: { action !r} " )
181
+ if not isinstance (lineno , int ):
182
+ raise TypeError ("lineno must be an int" )
183
+ if lineno < 0 :
184
+ raise ValueError ("lineno must be an int >= 0" )
179
185
_add_filter (action , None , category , None , lineno , append = append )
180
186
181
187
def _add_filter (* item , append ):
0 commit comments