Last active
December 1, 2024 06:50
-
-
Save DavidBuchanan314/7cdd3c34fedd0c5175d301a38e6922a1 to your computer and use it in GitHub Desktop.
Revisions
-
DavidBuchanan314 revised this gist
Dec 1, 2024 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,9 @@ })()(fn)() )), (throw := lambda e: (_ for _ in ()).throw(e) ), print(try_except( lambda: int("123"), -
DavidBuchanan314 revised this gist
Dec 1, 2024 . 1 changed file with 23 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,25 @@ [ (try_except := (lambda fn, exception_callback: type("mycontext", (__import__("contextlib").ContextDecorator,), { "__enter__": lambda self: self, "__exit__": lambda self, a, b, c: (a and exception_callback(a, b, c)) or True })()(fn)() )), (throw := lambda e: (_ for _ in ()).throw(e)), print(try_except( lambda: int("123"), lambda a, b, c: print("caught", a, b, c) )), print(try_except( lambda: int("abc"), lambda a, b, c: print("caught", a, b, c) )), print(try_except( lambda: throw(Exception("myexception")), lambda a, b, c: print("caught", a, b, c) )), ] -
DavidBuchanan314 revised this gist
Dec 1, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ try_except = (lambda fn, exception_callback: type("mycontext", (__import__("contextlib").ContextDecorator,), { "__enter__": lambda self: self, "__exit__": lambda self, a, b, c: (a and exception_callback(a, b, c)) or True })()(fn)() ) -
DavidBuchanan314 revised this gist
Dec 1, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ try_except = (lambda fn, exception_callback: type("mycontext", (__import__("contextlib").ContextDecorator,), { "__enter__": lambda self: self, "__exit__": lambda self, a, b, c: [a and exception_callback(a, b, c), True][-1] })()(fn)() ) -
DavidBuchanan314 revised this gist
Dec 1, 2024 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,10 @@ print(try_except( lambda: int("123"), lambda a, b, c: print("caught", a, b, c) )) print(try_except( lambda: int("abc"), lambda a, b, c: print("caught", a, b, c) )) -
DavidBuchanan314 created this gist
Dec 1, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ try_except = (lambda fn, exception_callback: type("mycontext", (__import__("contextlib").ContextDecorator,), { "__enter__": lambda self: self, "__exit__": lambda self, a, b, c: [(not a) or exception_callback(a, b, c), True][-1] })()(fn)() ) print(try_except( lambda: int("123"), lambda a, b, c: print("caught", a) )) print(try_except( lambda: int("abc"), lambda a, b, c: print("caught", a) ))