Merge pull request #2963 from mikejgray/2911__feat-proper-exceptions

chore: convert try/except on TypeError to ValueError
This commit is contained in:
Griatch 2022-11-01 17:22:31 +01:00 committed by GitHub
commit e9e12da793

View file

@ -661,6 +661,8 @@ def funcparser_callable_toint(*args, **kwargs):
return int(inp) return int(inp)
except TypeError: except TypeError:
return inp return inp
except ValueError:
return inp
def funcparser_callable_int2str(*args, **kwargs): def funcparser_callable_int2str(*args, **kwargs):
@ -902,7 +904,7 @@ def funcparser_callable_pad(*args, **kwargs):
nrest = len(rest) nrest = len(rest)
try: try:
width = int(kwargs.get("width", rest[0] if nrest > 0 else _CLIENT_DEFAULT_WIDTH)) width = int(kwargs.get("width", rest[0] if nrest > 0 else _CLIENT_DEFAULT_WIDTH))
except TypeError: except ValueError:
width = _CLIENT_DEFAULT_WIDTH width = _CLIENT_DEFAULT_WIDTH
align = kwargs.get("align", rest[1] if nrest > 1 else "c") align = kwargs.get("align", rest[1] if nrest > 1 else "c")
@ -934,7 +936,7 @@ def funcparser_callable_crop(*args, **kwargs):
nrest = len(rest) nrest = len(rest)
try: try:
width = int(kwargs.get("width", rest[0] if nrest > 0 else _CLIENT_DEFAULT_WIDTH)) width = int(kwargs.get("width", rest[0] if nrest > 0 else _CLIENT_DEFAULT_WIDTH))
except TypeError: except ValueError:
width = _CLIENT_DEFAULT_WIDTH width = _CLIENT_DEFAULT_WIDTH
suffix = kwargs.get("suffix", rest[1] if nrest > 1 else "[...]") suffix = kwargs.get("suffix", rest[1] if nrest > 1 else "[...]")
return crop(str(text), width=width, suffix=str(suffix)) return crop(str(text), width=width, suffix=str(suffix))
@ -951,7 +953,7 @@ def funcparser_callable_space(*args, **kwarg):
return "" return ""
try: try:
width = int(args[0]) width = int(args[0])
except TypeError: except ValueError:
width = 1 width = 1
return " " * width return " " * width
@ -980,12 +982,12 @@ def funcparser_callable_justify(*args, **kwargs):
lrest = len(rest) lrest = len(rest)
try: try:
width = int(kwargs.get("width", rest[0] if lrest > 0 else _CLIENT_DEFAULT_WIDTH)) width = int(kwargs.get("width", rest[0] if lrest > 0 else _CLIENT_DEFAULT_WIDTH))
except TypeError: except ValueError:
width = _CLIENT_DEFAULT_WIDTH width = _CLIENT_DEFAULT_WIDTH
align = str(kwargs.get("align", rest[1] if lrest > 1 else "f")) align = str(kwargs.get("align", rest[1] if lrest > 1 else "f"))
try: try:
indent = int(kwargs.get("indent", rest[2] if lrest > 2 else 0)) indent = int(kwargs.get("indent", rest[2] if lrest > 2 else 0))
except TypeError: except ValueError:
indent = 0 indent = 0
return justify(str(text), width=width, align=align, indent=indent) return justify(str(text), width=width, align=align, indent=indent)