Page 1 of 1

Neutral ATL transform aka Identity transform (to use as default argument)

Posted: Sun Dec 24, 2023 12:49 pm
by komehara
I'm passing an ATL transform to a parameter label so I can customise the way I display a BG image:

Code: Select all

label show_bg(bg_name, tr=None):
        show expression "bg " + bg_name at tr
However, I noticed that my default value of None causes an error:
TypeError: 'NoneType' object is not callable
So, the most logical would be to pass a "neutral" or "identity" transform that does nothing, when I want to show the BG as such.

This doesn't seem to be defined natively, which means I need to define my own dummy transform that does nothing:

Code: Select all

transform identity:
        pass
and use it as default value.

Or, in order to support both passing a transform and no transform, create two cases:

Code: Select all

label show_bg(bg_name, tr=None):
    if tr:
        show expression "bg " + bg_name at tr
    else:
        show expression "bg " + bg_name
which is more verbose.

UPDATE: tested both methods, they do work