summaryrefslogtreecommitdiff
path: root/gitlab
diff options
context:
space:
mode:
authorJohn L. Villalovos <john@sodarock.com>2022-01-07 12:12:24 -0800
committerJohn L. Villalovos <john@sodarock.com>2022-01-07 12:12:24 -0800
commite34a2e28f2aee2ab3314927bb51891b6ace78908 (patch)
treefc331ea13daca0b10d95174a861f50c4855906e0 /gitlab
parent989634055b0c5ab622ac7774b546928a564a31ef (diff)
downloadgitlab-jlvillal/pprint.tar.gz
chore: add `pprint()` and `pformat()` methods to RESTObjectjlvillal/pprint
This is useful in debugging and testing. As can easily print out the values from an instance in a more human-readable form.
Diffstat (limited to 'gitlab')
-rw-r--r--gitlab/base.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/gitlab/base.py b/gitlab/base.py
index 50f09c5..6a6e992 100644
--- a/gitlab/base.py
+++ b/gitlab/base.py
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import importlib
+import pprint
import textwrap
from types import ModuleType
from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type
@@ -147,6 +148,14 @@ class RESTObject(object):
data.update(self._updated_attrs)
return f"{type(self)} => {data}"
+ def pformat(self) -> str:
+ data = self._attrs.copy()
+ data.update(self._updated_attrs)
+ return f"{type(self)} => \n{pprint.pformat(data)}"
+
+ def pprint(self) -> None:
+ print(self.pformat())
+
def __repr__(self) -> str:
if self._id_attr:
return f"<{self.__class__.__name__} {self._id_attr}:{self.get_id()}>"