Created
October 24, 2022 21:21
-
-
Save frontdevops/06dc9b093f919a8a41f10630f088a4d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import builtins | |
class Exception311(BaseException): | |
""" | |
This is a fallback for exception behavior like in python 3.11 | |
""" | |
__notes__ = [] | |
def __init__(self, *args): | |
super().__init__(*args) | |
def add_note(self, note): | |
self.__notes__.append(note) | |
def __str__(self): | |
return super().__str__() + '\n' + '\n'.join(self.__notes__) | |
if "3.11" != f"{sys.version_info.major}.{sys.version_info.minor}": | |
print("🧙️Run fallback python 3.10") | |
builtins.Exception = Exception311 | |
try: | |
raise Exception("My message") | |
except Exception as e: | |
e.add_note("My note") | |
e.add_note("My note 2") | |
e.add_note("My note 3") | |
raise |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment