diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-06-19 08:09:59 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-19 08:09:59 -0500 |
| commit | 6c0fd99099a6251a12bc2287d5ba2ab115cd8015 (patch) | |
| tree | 58860ddb4a52566fec9aa95cbc7161179c1585b8 /python | |
| parent | 177c5e837073789431e945620dca6a2ee0b1927f (diff) | |
| parent | 7b97a7a407cfa407217012b3018bebfcd25b0da7 (diff) | |
| download | vyos-1x-6c0fd99099a6251a12bc2287d5ba2ab115cd8015.tar.gz vyos-1x-6c0fd99099a6251a12bc2287d5ba2ab115cd8015.zip | |
Merge pull request #5075 from vyos/fix/mutable-default-args
config: T8858: fix mutable default argument in config API methods
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/config.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/python/vyos/config.py b/python/vyos/config.py index 827246d05..7c9771ae3 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -480,21 +480,24 @@ class Config(object): else: return(value) - def return_values(self, path, default=[]): + def return_values(self, path, default=None): """ Retrieve all values of a multi-value leaf node in the running or proposed config Args: path (str): Configuration tree path + default (list): Value returned (as a copy) when the node does not exist or has no values. Defaults to an empty list. Returns: str list: Node values, if it has any - []: if node does not exist + default.copy(): if node does not exist or has no values Note: This function cannot be used outside a configuration session. In operational mode scripts, use ``return_effective_values``. """ + if default is None: + default = [] if self._session_config: try: values = self._session_config.return_values(self._make_path(path)) @@ -508,17 +511,20 @@ class Config(object): else: return(values) - def list_nodes(self, path, default=[]): + def list_nodes(self, path, default=None): """ Retrieve names of all children of a tag node in the running or proposed config Args: path (str): Configuration tree path + default (list): Value returned (as a copy) when the tag node does not exist or has no children. Defaults to an empty list. Returns: - string list: child node names + string list: child node names, or default.copy() if the node does not exist or has no children """ + if default is None: + default = [] if self._session_config: try: nodes = self._session_config.list_nodes(self._make_path(path)) @@ -596,16 +602,19 @@ class Config(object): else: return(value) - def return_effective_values(self, path, default=[]): + def return_effective_values(self, path, default=None): """ Retrieve all values of a multi-value node in a running (effective) config Args: path (str): Configuration tree path + default (list): Value returned (as a copy) when the node does not exist or has no values. Defaults to an empty list. Returns: - str list: A list of values + str list: A list of values, or default.copy() if the node does not exist or has no values """ + if default is None: + default = [] if self._running_config: try: values = self._running_config.return_values(self._make_path(path)) @@ -619,16 +628,19 @@ class Config(object): else: return(values) - def list_effective_nodes(self, path, default=[]): + def list_effective_nodes(self, path, default=None): """ Retrieve names of all children of a tag node in the running config Args: path (str): Configuration tree path + default (list): Value returned (as a copy) when the tag node does not exist or has no children. Defaults to an empty list. Returns: - str list: child node names + str list: child node names, or default.copy() if the node does not exist or has no children """ + if default is None: + default = [] if self._running_config: try: nodes = self._running_config.list_nodes(self._make_path(path)) |
