The namedtuple()
function is basically a class factory. Build that class once at the module level:
import collections
MyCustomType = collections.namedtuple('MyCustomType', 'a, b')
then import MyCustomType
everywhere instead. It's just a class, you don't have to re-create that class every time you want to build the tuple.
import somemodule
def NewFunction(param):
a = ...
b = ...
return somemodule.MyCustomType(a, b)