forked from M-Labs/artiq
1
0
Fork 0

language.environment: error out if unknown arguments are passed (#1927)

Closes #1641
This commit is contained in:
Deepskyhunter 2022-07-26 10:42:03 +08:00 committed by GitHub
parent 748e28be38
commit 2a7a72b27a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -209,18 +209,28 @@ class TraceArgumentManager:
self.requested_args[key] = processor, group, tooltip
return None
def check_unprocessed_arguments(self):
pass
class ProcessArgumentManager:
def __init__(self, unprocessed_arguments):
self.unprocessed_arguments = unprocessed_arguments
self._processed_arguments = set()
def get(self, key, processor, group, tooltip):
if key in self.unprocessed_arguments:
r = processor.process(self.unprocessed_arguments[key])
self._processed_arguments.add(key)
else:
r = processor.default()
return r
def check_unprocessed_arguments(self):
unprocessed = set(self.unprocessed_arguments.keys()) -\
self._processed_arguments
if unprocessed:
raise AttributeError("Invalid argument(s): " +
", ".join(unprocessed))
class HasEnvironment:
"""Provides methods to manage the environment of an experiment (arguments,
@ -242,6 +252,7 @@ class HasEnvironment:
self.__in_build = True
self.build(*args, **kwargs)
self.__in_build = False
self.__argument_mgr.check_unprocessed_arguments()
def register_child(self, child):
self.children.append(child)