This function is doing a few things (resolving/validating config, collecting argument dict, collecting late variables) that seem like they could be split up. Collecting late variables is a clear candidate for a separate function -- that this function returns two unrelated values is awkward.