Options: implement additional assert checking for duplicate option ID (#332)

Options: change "random" prevention to assert, so it doesn't get checked in compiled version, as it's a source-code-time issue.
This commit is contained in:
Fabian Dill 2022-03-23 02:28:15 +01:00 committed by GitHub
parent 5eccb0ed49
commit 171c297d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -16,8 +16,10 @@ class AssembleOptions(type):
name_lookup.update(base.name_lookup)
new_options = {name[7:].lower(): option_id for name, option_id in attrs.items() if
name.startswith("option_")}
if "random" in new_options:
raise Exception("Choice option 'random' cannot be manually assigned.")
assert "random" not in new_options # Choice option 'random' cannot be manually assigned.
assert len(new_options) == len(set(new_options.values())) # same ID cannot be used twice. Try alias?
attrs["name_lookup"].update({option_id: name for name, option_id in new_options.items()})
options.update(new_options)