summary refs log tree commit diff
path: root/synapse/config/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2019-07-15 13:15:34 +0100
committerErik Johnston <erik@matrix.org>2019-07-15 14:09:33 +0100
commit823e13ddf49b28eb0dab5d7be3921acc92fd0e44 (patch)
tree0b3797ff105409b57ed524ac8e73886c06dbe2a6 /synapse/config/_base.py
parentNewsfile (diff)
downloadsynapse-823e13ddf49b28eb0dab5d7be3921acc92fd0e44.tar.xz
Change add_arguments to be a static method
Diffstat (limited to 'synapse/config/_base.py')
-rw-r--r--synapse/config/_base.py32
1 files changed, 31 insertions, 1 deletions
diff --git a/synapse/config/_base.py b/synapse/config/_base.py

index 14d3f7c1fe..e588f82981 100644 --- a/synapse/config/_base.py +++ b/synapse/config/_base.py
@@ -137,12 +137,42 @@ class Config(object): return file_stream.read() def invoke_all(self, name, *args, **kargs): + """Invoke all instance methods with the given name and arguments in the + class's MRO. + + Args: + name (str): Name of function to invoke + *args + **kwargs + + Returns: + list: The list of the return values from each method called + """ results = [] for cls in type(self).mro(): if name in cls.__dict__: results.append(getattr(cls, name)(self, *args, **kargs)) return results + @classmethod + def invoke_all_static(cls, name, *args, **kargs): + """Invoke all static methods with the given name and arguments in the + class's MRO. + + Args: + name (str): Name of function to invoke + *args + **kwargs + + Returns: + list: The list of the return values from each method called + """ + results = [] + for c in cls.mro(): + if name in c.__dict__: + results.append(getattr(c, name)(*args, **kargs)) + return results + def generate_config( self, config_dir_path, @@ -241,7 +271,7 @@ class Config(object): # We can only invoke `add_arguments` on an actual object, but # `add_arguments` should be side effect free so this is probably fine. - cls().invoke_all("add_arguments", config_parser) + cls.invoke_all_static("add_arguments", config_parser) return config_parser