fun_error.py 919 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # test errors from bad function calls
  2. # function doesn't take keyword args
  3. try:
  4. [].append(x=1)
  5. except TypeError:
  6. print('TypeError')
  7. # function with variable number of positional args given too few
  8. try:
  9. round()
  10. except TypeError:
  11. print('TypeError')
  12. # function with variable number of positional args given too many
  13. try:
  14. round(1, 2, 3)
  15. except TypeError:
  16. print('TypeError')
  17. # function with fixed number of positional args given wrong number
  18. try:
  19. [].append(1, 2)
  20. except TypeError:
  21. print('TypeError')
  22. # function with keyword args given extra positional args
  23. try:
  24. [].sort(1)
  25. except TypeError:
  26. print('TypeError')
  27. # function with keyword args given extra keyword args
  28. try:
  29. [].sort(noexist=1)
  30. except TypeError:
  31. print('TypeError')
  32. # kw given for positional, but a different positional is missing
  33. try:
  34. def f(x, y): pass
  35. f(x=1)
  36. except TypeError:
  37. print('TypeError')