Given the following code:
status = row[COL_STATUS]
if status == "idle":
row[COL_EDITABLE] = True
row[COL_FONTSTYLE] = pango.STYLE_NORMAL
row[COL_WEIGHT] = pango.WEIGHT_NORMAL
elif status == "DCed":
row[COL_EDITABLE] = True
row[COL_FONTSTYLE] = pango.STYLE_ITALIC
row[COL_WEIGHT] = pango.WEIGHT_NORMAL
else:
row[COL_EDITABLE] = False
row[COL_FONTSTYLE] = pango.STYLE_NORMAL
row[COL_WEIGHT] = pango.WEIGHT_BOLD
Would the following be a net beneficial refactoring, in your opinion?
d = {"idle": (True, pango.STYLE_NORMAL, pango.WEIGHT_NORMAL),
"DCed": (True, pango.STYLE_ITALIC, pango.WEIGHT_NORMAL),
None: (False, pango.STYLE_NORMAL, pango.WEIGHT_BOLD)}
e,f,w = d.get(status, d[None])
row[COL_EDITABLE] = e
row[COL_FONTSTYLE] = f
row[COL_WEIGHT] = w
What if there were more cases or more row components to edit?