|
| 1 | +import sys |
| 2 | + |
| 3 | +if sys.version_info < (3, 11): |
| 4 | + from exceptiongroup import BaseExceptionGroup, ExceptionGroup |
| 5 | + |
| 6 | + |
| 7 | +class NoDerive(ExceptionGroup): # error: 0, "NoDerive", "NoDerive" |
| 8 | + pass |
| 9 | + |
| 10 | + |
| 11 | +class NoDeriveBase(BaseExceptionGroup): # error: 0, "NoDeriveBase", "NoDeriveBase" |
| 12 | + pass |
| 13 | + |
| 14 | + |
| 15 | +class NoDeriveGeneric(ExceptionGroup[Exception]): # error: 0, "NoDeriveGeneric", "NoDeriveGeneric" |
| 16 | + pass |
| 17 | + |
| 18 | + |
| 19 | +import exceptiongroup |
| 20 | + |
| 21 | + |
| 22 | +class NoDeriveQualified(exceptiongroup.ExceptionGroup): # error: 0, "NoDeriveQualified", "NoDeriveQualified" |
| 23 | + pass |
| 24 | + |
| 25 | + |
| 26 | +class SomeMixin: ... |
| 27 | + |
| 28 | + |
| 29 | +class MultipleBases(SomeMixin, ExceptionGroup): # error: 0, "MultipleBases", "MultipleBases" |
| 30 | + pass |
| 31 | + |
| 32 | + |
| 33 | +# safe - overrides derive |
| 34 | +class HasDerive(ExceptionGroup): |
| 35 | + def derive(self, excs): |
| 36 | + return HasDerive(self.message, excs) |
| 37 | + |
| 38 | + |
| 39 | +class HasDeriveBase(BaseExceptionGroup): |
| 40 | + def derive(self, excs): |
| 41 | + return HasDeriveBase(self.message, excs) |
| 42 | + |
| 43 | + |
| 44 | +class HasDeriveGeneric(ExceptionGroup[Exception]): |
| 45 | + def derive(self, excs): |
| 46 | + return HasDeriveGeneric(self.message, excs) |
| 47 | + |
| 48 | + |
| 49 | +# async derive is weird but counts |
| 50 | +class AsyncDerive(ExceptionGroup): |
| 51 | + async def derive(self, excs): # type: ignore |
| 52 | + return AsyncDerive(self.message, excs) |
| 53 | + |
| 54 | + |
| 55 | +# not an ExceptionGroup subclass |
| 56 | +class NotAnEG(Exception): |
| 57 | + pass |
| 58 | + |
| 59 | + |
| 60 | +# nested class |
| 61 | +class Outer: |
| 62 | + class InnerNoDerive(ExceptionGroup): # error: 4, "InnerNoDerive", "InnerNoDerive" |
| 63 | + pass |
| 64 | + |
| 65 | + class InnerHasDerive(ExceptionGroup): |
| 66 | + def derive(self, excs): |
| 67 | + return Outer.InnerHasDerive(self.message, excs) |
0 commit comments