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