Make arcpy.AddWarning wrapped in script warnings!

470
1
07-05-2022 09:29 PM
Status: Open
HildermesJoséMedeirosFilho
New Contributor III

arcpy.Add Warning could just throw a normal warning. Doe make sense to you people need to do a wrapper every time in a pyt, toolbox and the like just to test?

def scriptwarning(func):
"""
Arcpy Warning Wraper
:param func:
:return:
"""

def wrap(*args, **kwargs):

result = func(*args, **kwargs)
warnings.warn(*args)
return result
return wrap

arcpy.AddWarning = scriptwarning(arcpy.AddWarning)

I don`t like doing it, it seams crazily wrong, for something simple.
If arcpy throws a warning why should I wrap it to test and get an expected warning?

1 Comment
Luke_Pinner

Good idea. But Esri would also have to implement this idea: 

Interpret warnings as warnings instead of errors in Python tools