|
| 1 | +""" |
| 2 | +This is a copy of b014 but with except* instead. Should emit: |
| 3 | +B014 - on lines 11, 17, 28, 42, 49, 56, and 74. |
| 4 | +""" |
| 5 | + |
| 6 | +import binascii |
| 7 | +import re |
| 8 | + |
| 9 | +try: |
| 10 | + pass |
| 11 | +except* (Exception, TypeError): |
| 12 | + # TypeError is a subclass of Exception, so it doesn't add anything |
| 13 | + pass |
| 14 | + |
| 15 | +try: |
| 16 | + pass |
| 17 | +except* (OSError, OSError) as err: |
| 18 | + # Duplicate exception types are useless |
| 19 | + pass |
| 20 | + |
| 21 | + |
| 22 | +class MyError(Exception): |
| 23 | + pass |
| 24 | + |
| 25 | + |
| 26 | +try: |
| 27 | + pass |
| 28 | +except* (MyError, MyError): |
| 29 | + # Detect duplicate non-builtin errors |
| 30 | + pass |
| 31 | + |
| 32 | + |
| 33 | +try: |
| 34 | + pass |
| 35 | +except* (MyError, Exception) as e: |
| 36 | + # Don't assume that we're all subclasses of Exception |
| 37 | + pass |
| 38 | + |
| 39 | + |
| 40 | +try: |
| 41 | + pass |
| 42 | +except* (MyError, BaseException) as e: |
| 43 | + # But we *can* assume that everything is a subclass of BaseException |
| 44 | + raise e |
| 45 | + |
| 46 | + |
| 47 | +try: |
| 48 | + pass |
| 49 | +except* (re.error, re.error): |
| 50 | + # Duplicate exception types as attributes |
| 51 | + pass |
| 52 | + |
| 53 | + |
| 54 | +try: |
| 55 | + pass |
| 56 | +except* (IOError, EnvironmentError, OSError): |
| 57 | + # Detect if a primary exception and any its aliases are present. |
| 58 | + # |
| 59 | + # Since Python 3.3, IOError, EnvironmentError, WindowsError, mmap.error, |
| 60 | + # socket.error and select.error are aliases of OSError. See PEP 3151 for |
| 61 | + # more info. |
| 62 | + pass |
| 63 | + |
| 64 | + |
| 65 | +try: |
| 66 | + pass |
| 67 | +except* (MyException, NotImplemented): |
| 68 | + # NotImplemented is not an exception, let's not crash on it. |
| 69 | + pass |
| 70 | + |
| 71 | + |
| 72 | +try: |
| 73 | + pass |
| 74 | +except* (ValueError, binascii.Error): |
| 75 | + # binascii.Error is a subclass of ValueError. |
| 76 | + pass |
0 commit comments