Vorrei indicare una funzione che non fa nulla:
def identity(*args)
return args
il mio caso d'uso è qualcosa del genere
try:
gettext.find(...)
...
_ = gettext.gettext
else:
_ = identity
Certo, potrei usare il identitysopra definito, ma un built-in sarebbe sicuramente più veloce (ed eviterebbe i bug introdotti dal mio).
Apparentemente, mape filterusare Noneper l'identità, ma questo è specifico per le loro implementazioni.
>>> _=None
>>> _("hello")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
map(None, [1, 2, 3])
map and filter use None for the identity?