@@ -641,9 +641,10 @@ def _do_substitute(cls, substitution, resolved_value, is_optional_resolved=True)
641
641
if transformation is None and not is_optional_resolved \
642
642
else transformation
643
643
644
+ # When the result is None, remove the key.
644
645
if result is None and config_values .key in config_values .parent :
645
646
del config_values .parent [config_values .key ]
646
- else :
647
+ elif result is not None :
647
648
config_values .parent [config_values .key ] = result
648
649
s = cls ._find_substitutions (result )
649
650
if s :
@@ -692,6 +693,12 @@ def resolve_substitutions(cls, config, accept_unresolved=False):
692
693
_substitutions = substitutions [:]
693
694
694
695
for substitution in _substitutions :
696
+ # If this substitution is an override, and the parent is still being processed,
697
+ # skip this entry, it will be processed on the next loop.
698
+ if substitution .parent .overriden_value :
699
+ if substitution .parent .overriden_value in [s .parent for s in substitutions ]:
700
+ continue
701
+
695
702
is_optional_resolved , resolved_value = cls ._resolve_variable (config , substitution )
696
703
697
704
# if the substitution is optional
@@ -717,6 +724,8 @@ def resolve_substitutions(cls, config, accept_unresolved=False):
717
724
718
725
unresolved , new_substitutions , result = cls ._do_substitute (substitution , resolved_value , is_optional_resolved )
719
726
any_unresolved = unresolved or any_unresolved
727
+ # Detected substitutions may already be listed to process
728
+ new_substitutions = [n for n in new_substitutions if n not in substitutions ]
720
729
substitutions .extend (new_substitutions )
721
730
if not isinstance (result , ConfigValues ):
722
731
substitutions .remove (substitution )
0 commit comments