[loader] Simplify _attach test for optional dependencies