This commit is contained in:
Jesse Bannon 2025-12-26 14:43:37 -08:00
parent 55cf6bc48d
commit efb5e889b3
3 changed files with 10 additions and 8 deletions

View file

@ -1,5 +1,6 @@
from typing import Any, List, Iterable from typing import Any
from typing import Dict from typing import Dict
from typing import Iterable
from typing import Optional from typing import Optional
from typing import Set from typing import Set
@ -89,6 +90,11 @@ class Overrides(UnstructuredDictFormatterValidator, Scriptable):
return True return True
def ensure_variable_names_not_a_plugin(self, plugin_names: Iterable[str]) -> None: def ensure_variable_names_not_a_plugin(self, plugin_names: Iterable[str]) -> None:
"""
Throws an error if an override variable or function has the same name as a
preset key. This is to avoid confusion when accidentally defining things in
overrides that are meant to be in the preset.
"""
for name in self.keys: for name in self.keys:
if name.startswith("%"): if name.startswith("%"):
name = name[1:] name = name[1:]

View file

@ -194,9 +194,7 @@ class Preset(_PresetShell):
self.plugins: PresetPlugins = self._validate_and_get_plugins() self.plugins: PresetPlugins = self._validate_and_get_plugins()
self.overrides = self._validate_key(key="overrides", validator=Overrides, default={}) self.overrides = self._validate_key(key="overrides", validator=Overrides, default={})
self.overrides.ensure_variable_names_not_a_plugin( self.overrides.ensure_variable_names_not_a_plugin(plugin_names=PRESET_KEYS)
plugin_names=PRESET_KEYS
)
VariableValidation( VariableValidation(
downloader_options=self.downloader_options, downloader_options=self.downloader_options,

View file

@ -456,8 +456,6 @@ class TestPreset:
"embed_subtitles": True, "embed_subtitles": True,
}, },
"output_options": {"output_directory": "dir", "file_name": "acjk"}, "output_options": {"output_directory": "dir", "file_name": "acjk"},
"overrides": { "overrides": {"throttle_protection": "nope"},
"throttle_protection": "nope"
}
}, },
) )