Maybe you could avoid the repeated code with a decorator?