[Pkg-gnupg-commit] [gpgme] 05/132: python: Make Results have a nicer __repr__.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Apr 26 01:00:46 UTC 2017


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch experimental
in repository gpgme.

commit db2f6c1ca3d2ef228f4ca6653d594537622c8588
Author: Tobias Mueller <muelli at cryptobitch.de>
Date:   Wed Nov 30 08:47:29 2016 +0100

    python: Make Results have a nicer __repr__.
    
    * lang/python/gpg/results.py (Result.__str__): Renamed to '__repr__'
    ...
    * lang/python/gpg/results.py (Result.__repr__): ... and added fields.
    --
    
    So that it looks a bit nicer in the Python REPL.
    
    It looked like this before:
    
    In [2]: gpg.core.get_engine_info()[0]
    Out[2]:
    <gpg.results.EngineInfo at 0x7fb23509a240>
    
    Now the output is
    
    In [2]: gpg.core.get_engine_info()[0]
    Out[2]:
    EngineInfo(file_name='/usr/bin/gpg2', home_dir=None,
    protocol=0, req_version='1.4.0', version='2.1.11')
    
    This also applies to other results, e.g. the ImportResult.
    
    Note that the format now changed from "<Class >" to "Class()". The
    Python documentation on repr states: "For many object types, including
    most builtins, eval(repr(obj)) == obj."
    
    Signed-off-by: Tobias Mueller <muelli at cryptobitch.de>
---
 lang/python/gpg/results.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lang/python/gpg/results.py b/lang/python/gpg/results.py
index 3383896..46ebeec 100644
--- a/lang/python/gpg/results.py
+++ b/lang/python/gpg/results.py
@@ -64,10 +64,10 @@ class Result(object):
 
             setattr(self, key, getattr(fragile, key))
 
-    def __str__(self):
-        return '<{} {}>'.format(
+    def __repr__(self):
+        return '{}({})'.format(
             self.__class__.__name__,
-            ', '.join('{}: {}'.format(k, getattr(self, k))
+            ', '.join('{}={!r}'.format(k, getattr(self, k))
                       for k in dir(self) if not k.startswith('_')))
 
 class InvalidKey(Result):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list