0

consider my scenario, I have a method which is kind of a factory that returns me the action based on the status that I pass.

def factory(status):
    action = {
        1: action_1,
        2: action_2,
        3: action_3,
    }.get(status)

    return action

and these are the actions,

def action_1():
    # making db call
    action_1_db_call()

def action_2():
    # making db call
    action_2_db_call()

def action_3():
    # It will do nothing
    pass

I will basically do the following in the main code,

action = factory(1)
action()

So here, which is the right approach for action_3? Can I just use pass for this method or I should return None. which one is advisable and a good practice?

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Manoj Kumar S
  • 634
  • 8
  • 16
  • 2
    If all it does is pass, that *will* return none. You only need the pass because the function must have *some* body, there are other ways to write it (e.g. `action_3 = lambda: None`). – jonrsharpe Aug 21 '19 at 16:59
  • If the function has docstring, you can omit `pass` too – Andrej Kesely Aug 21 '19 at 17:01

0 Answers0