CIL
CIL copied to clipboard
remove `hasattr`s
vis TomographicImaging/CIL?q=hasattr
much bug such bad:
class Foo:
def run(self):
if not hasattr(self, 'bar'):
self.bar = 0
self.bar += 1
def stop(self):
self.bar -= 1 # might raise AttributeError
correct:
class Foo:
def __init__(self):
self.bar = 0
def run(self):
self.bar += 1
def stop(self):
self.bar -= 1
With optional attributes:
class Foo:
def __init__(self):
self.bar = 0
self.baz = None
def run(self):
self.bar = 0
if self.baz is not None:
self.baz += 1