From d69ba0479a4537bbc7a53f342661c1984382f939 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Sat, 8 Jan 2022 17:56:26 -0800 Subject: chore: add `pprint()` and `pformat()` methods to RESTObject This is useful in debugging and testing. As can easily print out the values from an instance in a more human-readable form. --- gitlab/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'gitlab') 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 . 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()}>" -- cgit v1.2.1