Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

redefine_in_handler.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. """Test for W0623, overwriting names in exception handlers."""
  2. # pylint: disable=broad-except,bare-except,print-statement,no-absolute-import,duplicate-except
  3. # pylint: disable=invalid-name, unused-variable
  4. import exceptions
  5. __revision__ = ''
  6. class MyError(Exception):
  7. """Special exception class."""
  8. pass
  9. def some_function():
  10. """A function."""
  11. exc = None
  12. try:
  13. {}["a"]
  14. except KeyError, exceptions.RuntimeError: # [redefine-in-handler]
  15. pass
  16. except KeyError, OSError: # [redefine-in-handler]
  17. pass
  18. except KeyError, MyError: # [redefine-in-handler]
  19. pass
  20. except KeyError, exc: # this is fine
  21. print exc
  22. except KeyError, exc1: # this is fine
  23. print exc1
  24. except KeyError, FOO: # C0103
  25. print FOO
  26. try:
  27. pass
  28. except KeyError, exc1: # this is fine
  29. print exc1
  30. class MyOtherError(Exception):
  31. """Special exception class."""
  32. pass
  33. exc3 = None
  34. try:
  35. pass
  36. except KeyError, exceptions.RuntimeError: # [redefine-in-handler]
  37. pass
  38. except KeyError, exceptions.RuntimeError.args: # [redefine-in-handler]
  39. pass
  40. except KeyError, OSError: # [redefine-in-handler]
  41. pass
  42. except KeyError, MyOtherError: # [redefine-in-handler]
  43. pass
  44. except KeyError, exc3: # this is fine
  45. print exc3
  46. except KeyError, exc4: # this is fine
  47. print exc4
  48. except KeyError, OOPS: # C0103
  49. print OOPS
  50. try:
  51. pass
  52. except KeyError, exc4: # this is fine
  53. print exc4
  54. except IOError, exc5: # this is fine
  55. print exc5
  56. except MyOtherError, exc5: # this is fine
  57. print exc5