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.

misplaced_bare_raise.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # pylint: disable=missing-docstring, broad-except, unreachable
  2. # pylint: disable=unused-variable, too-few-public-methods, invalid-name
  3. try:
  4. raise # [misplaced-bare-raise]
  5. except Exception:
  6. pass
  7. try:
  8. pass
  9. except Exception:
  10. raise
  11. # pylint: disable=misplaced-comparison-constant
  12. try:
  13. pass
  14. except Exception:
  15. if 1 == 2:
  16. raise
  17. def test():
  18. try:
  19. pass
  20. except Exception:
  21. def chest():
  22. try:
  23. pass
  24. except Exception:
  25. raise
  26. raise
  27. def test1():
  28. try:
  29. if 1 > 2:
  30. def best():
  31. raise # [misplaced-bare-raise]
  32. except Exception:
  33. pass
  34. raise # [misplaced-bare-raise]
  35. raise # [misplaced-bare-raise]
  36. try:
  37. pass
  38. finally:
  39. # This might work or might not to, depending if there's
  40. # an error raised inside the try block. But relying on this
  41. # behaviour can be error prone, so we decided to warn
  42. # against it.
  43. raise # [misplaced-bare-raise]
  44. class A(object):
  45. try:
  46. pass
  47. except Exception:
  48. raise
  49. raise # [misplaced-bare-raise]
  50. # This works in Python 2, but the intent is nevertheless
  51. # unclear. It will also not work on Python 3, so it's best
  52. # not to rely on it.
  53. exc = None
  54. try:
  55. 1/0
  56. except ZeroDivisionError as exc:
  57. pass
  58. if exc:
  59. raise # [misplaced-bare-raise]
  60. # Don't emit if we're in ``__exit__``.
  61. class ContextManager(object):
  62. def __enter__(self):
  63. return self
  64. def __exit__(self, *args):
  65. raise