2015-04-04 17:05:30 -04:00
|
|
|
# test errors from bad function calls
|
|
|
|
|
|
|
|
# function doesn't take keyword args
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
[].append(x=1)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
2015-04-04 17:05:30 -04:00
|
|
|
|
|
|
|
# function with variable number of positional args given too few
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
round()
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
2015-04-04 17:05:30 -04:00
|
|
|
|
|
|
|
# function with variable number of positional args given too many
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
round(1, 2, 3)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
2015-04-04 17:05:30 -04:00
|
|
|
|
|
|
|
# function with fixed number of positional args given wrong number
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
[].append(1, 2)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
2015-04-04 17:05:30 -04:00
|
|
|
|
|
|
|
# function with keyword args given extra positional args
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
[].sort(1)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
2015-04-04 17:05:30 -04:00
|
|
|
|
|
|
|
# function with keyword args given extra keyword args
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
[].sort(noexist=1)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|
2015-04-04 17:05:30 -04:00
|
|
|
|
2015-04-04 19:03:43 -04:00
|
|
|
# kw given for positional, but a different positional is missing
|
2018-02-14 00:50:20 -05:00
|
|
|
try:
|
|
|
|
def f(x, y): pass
|
|
|
|
f(x=1)
|
|
|
|
except TypeError:
|
|
|
|
print('TypeError')
|