with this pattern i don't think you're getting any value out of using a defaultdict (i.e., just change to if (loc_type, parent) in self._existing_by_type)