In a Mako template partial I accept an argument (step) that can be an instance of Step class, a dict or None. Can I in some way avoid repetition or do the check in other more 'pythonic' way? Or how could I gracefully avoid checking types at all?<%include file=_step.mako args=step=step />and then in _step.mako:<%page args=step/><%! from package.models.recipe import Step %><% if isinstance(step, Step):    number = step.number    time_value = step.time_value    text = step.textelif type(step) is dict:    number = step['number']    time_value = step['time_value']    text = step['text']else:    number = 1    time_value = ''    text = ''%>
How to (and should I) avoid repetition while assigning values from different sources?
python
1.I assume if type(step) is dict: should be elif type(step) is dict:.2.isinstance is preferable than type because isinstance caters for inheritance, while checking for equality of type does not (it demands identity of types and rejects instances of subtypes).3.You also can apply duck-typing. try:    number = step.numberexcept AttributeError:    try:        number = step['number']    except KeyError:        number = 1And these ways are quite pythonic.4.I suggest you can inherit your Step class from dict then you don't need to check types. Yo will just donumber = step.get('number', 1)time_value = step.get('time_value', '')