Adds type error for handling NoneType exceptions

This commit is contained in:
Mirko Galimberti
2018-07-27 12:03:39 +02:00
parent a22aac1e65
commit a053df7b75
+4 -3
View File
@@ -103,17 +103,18 @@ class CacheRepresenter(object):
cache[field][value] = nvalue cache[field][value] = nvalue
return nvalue return nvalue
def safe_int(x, i=0): def safe_int(x, i=0):
try: try:
return int(x) return int(x)
except ValueError: except (ValueError, TypeError):
return i return i
def safe_float(x): def safe_float(x):
try: try:
return float(x) return float(x)
except ValueError: except (ValueError, TypeError):
return 0 return 0
@@ -2055,7 +2056,7 @@ class SQLFORM(FORM):
reduce(lambda a,b: a|b, [ reduce(lambda a,b: a|b, [
field.contains(k) for field in sfields] field.contains(k) for field in sfields]
) for k in key.split()]) ) for k in key.split()])
# from https://groups.google.com/forum/#!topic/web2py/hKe6lI25Bv4 # from https://groups.google.com/forum/#!topic/web2py/hKe6lI25Bv4
# needs testing... # needs testing...
#words = key.split(' ') if key else [] #words = key.split(' ') if key else []