From 6d551208f4bc68d091a16323ae0d267fbb6003b6 Mon Sep 17 00:00:00 2001 From: "John L. Villalovos" Date: Sat, 24 Apr 2021 12:10:59 -0700 Subject: [PATCH] chore: make RESTObject._short_print_attrs always present Always create RESTObject._short_print_attrs with a default value of None. This way we don't need to use hasattr() and we will know the type of the attribute. --- gitlab/base.py | 1 + gitlab/v4/cli.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gitlab/base.py b/gitlab/base.py index 8f4e49ba6..7121cb0bb 100644 --- a/gitlab/base.py +++ b/gitlab/base.py @@ -45,6 +45,7 @@ class RESTObject(object): _attrs: Dict[str, Any] _module: ModuleType _parent_attrs: Dict[str, Any] + _short_print_attr: Optional[str] = None _updated_attrs: Dict[str, Any] manager: "RESTManager" diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index d036d127d..b03883e7c 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -380,7 +380,7 @@ def display_dict(d, padding): if obj._id_attr: id = getattr(obj, obj._id_attr) print("%s: %s" % (obj._id_attr.replace("_", "-"), id)) - if hasattr(obj, "_short_print_attr"): + if obj._short_print_attr: value = getattr(obj, obj._short_print_attr) or "None" value = value.replace("\r", "").replace("\n", " ") # If the attribute is a note (ProjectCommitComment) then we do