mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 19:01:15 +00:00
adds a nicer __repr__
This commit is contained in:
+20
-1
@@ -24,12 +24,15 @@
|
||||
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
# ##############################################################################
|
||||
|
||||
import sys
|
||||
import datetime
|
||||
from operator import itemgetter
|
||||
|
||||
import GithubException
|
||||
import Consts
|
||||
|
||||
atLeastPython3 = sys.hexversion >= 0x03000000
|
||||
|
||||
|
||||
class _NotSetType:
|
||||
def __repr__(self):
|
||||
@@ -207,6 +210,22 @@ class GithubObject(object):
|
||||
'''
|
||||
return self._headers.get(Consts.RES_LAST_MODIFED)
|
||||
|
||||
def get__repr__(self, params):
|
||||
"""
|
||||
Converts the object to a nicely printable string.
|
||||
"""
|
||||
def format_params(params):
|
||||
if atLeastPython3:
|
||||
items = params.items()
|
||||
else:
|
||||
items = list(params.items())
|
||||
for k, v in sorted(items, key=itemgetter(1)):
|
||||
yield '{k}="{v}"'.format(k=k, v=v) if isinstance(v, (str, unicode)) else '{k}={v}'.format(k=k, v=v)
|
||||
return '{class_name}({params})'.format(
|
||||
class_name=self.__class__.__name__,
|
||||
params=", ".join(list(format_params(params)))
|
||||
)
|
||||
|
||||
|
||||
class NonCompletableGithubObject(GithubObject):
|
||||
def _completeIfNeeded(self):
|
||||
|
||||
Reference in New Issue
Block a user