diff options
author | John L. Villalovos <john@sodarock.com> | 2022-05-31 17:54:59 -0700 |
---|---|---|
committer | John L. Villalovos <john@sodarock.com> | 2022-05-31 17:54:59 -0700 |
commit | 9d629bb97af1e14ce8eb4679092de2393e1e3a05 (patch) | |
tree | 19c442b982350c63c4077e001562d311062d7180 /gitlab/utils.py | |
parent | 0c5a1213ba3bb3ec4ed5874db4588d21969e9e80 (diff) | |
download | gitlab-9d629bb97af1e14ce8eb4679092de2393e1e3a05.tar.gz |
chore: move `utils._validate_attrs` inside `types.RequiredOptional`
Move the `validate_attrs` function to be inside the `RequiredOptional`
class. It makes sense for it to be part of the class as it is working
on data related to the class.
Diffstat (limited to 'gitlab/utils.py')
-rw-r--r-- | gitlab/utils.py | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/gitlab/utils.py b/gitlab/utils.py index 3cdd967..bab6705 100644 --- a/gitlab/utils.py +++ b/gitlab/utils.py @@ -19,7 +19,7 @@ import pathlib import traceback import urllib.parse import warnings -from typing import Any, Callable, Dict, List, Optional, Tuple, Type, Union +from typing import Any, Callable, Dict, Optional, Tuple, Type, Union import requests @@ -159,30 +159,3 @@ def warn( stacklevel=stacklevel, source=source, ) - - -def _validate_attrs( - data: Dict[str, Any], - attributes: types.RequiredOptional, - excludes: Optional[List[str]] = None, -) -> None: - if excludes is None: - excludes = [] - - if attributes.required: - required = [k for k in attributes.required if k not in excludes] - missing = [attr for attr in required if attr not in data] - if missing: - raise AttributeError(f"Missing attributes: {', '.join(missing)}") - - if attributes.exclusive: - exclusives = [attr for attr in data if attr in attributes.exclusive] - if len(exclusives) > 1: - raise AttributeError( - f"Provide only one of these attributes: {', '.join(exclusives)}" - ) - if not exclusives: - raise AttributeError( - f"Must provide one of these attributes: " - f"{', '.join(attributes.exclusive)}" - ) |