Created
January 15, 2021 22:16
-
-
Save anddam/06bf26c7759dc24e23f0bc5d0a2116c5 to your computer and use it in GitHub Desktop.
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 characters
def some_function(self, some_object): | |
attribute = some_object.get('attribute') | |
assert attribute is not None, Exception("attribute not present in some_function()") | |
try: | |
attribute.prepare_could_throw_exception() | |
except: | |
pass | |
try: | |
attribute.do_this() | |
attribute.do_that() | |
finally: | |
attribute.clear() | |
def another_function(self, some_object): | |
attribute = some_object.get('attribute') | |
assert attribute is not None, Exception("attribute not present in another_function()") | |
try: | |
attribute.prepare_could_throw_exception() | |
except: | |
pass | |
try: | |
attribute.foo() | |
attribute.bar() | |
finally: | |
attribute.clear() | |
def third_function(self, some_object): | |
attribute = some_object.get('attribute') | |
assert attribute is not None, Exception("attribute not present in third_function()") | |
try: | |
attribute.prepare_could_throw_exception() | |
except: | |
pass | |
try: | |
attribute.something() | |
attribute.new() | |
finally: | |
attribute.clear() |
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 characters
def common(self, some_object, exception message): | |
attribute = some_object.get(reader_name) | |
assert attribute is not None, Exception(exception_message) | |
try: | |
attribute.open_could_raise_exception() | |
except: | |
pass | |
return attribute | |
def some_function(self, some_object): | |
attribute = common(some_object, "attribute not present in some_function()") | |
try: | |
attribute.do_this() | |
attribute.do_that() | |
finally: | |
attribute.close() | |
def another_function(self, some_object): | |
attribute = common(some_object, "attribute not present in another_function()") | |
try: | |
attribute.foo() | |
attribute.bar() | |
finally: | |
attribute.close() | |
def third_function(self, some_object): | |
attribute = common(some_object, "attribute not present in third_function()") | |
try: | |
attribute.something() | |
attribute.something_else() | |
finally: | |
attribute.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment