import reduce from compatibility in doctest
treeapply uses isinstance