Skip to content

Instantly share code, notes, and snippets.

@anddam
Created January 15, 2021 22:16
Show Gist options
  • Save anddam/06bf26c7759dc24e23f0bc5d0a2116c5 to your computer and use it in GitHub Desktop.
Save anddam/06bf26c7759dc24e23f0bc5d0a2116c5 to your computer and use it in GitHub Desktop.
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()
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