diff mercurial/pycompat.py @ 32615:c9318beb7c1a

py3: convert __doc__ back to bytes in help.py pycompat.getdoc() is pretty simple, but we wouldn't want to write handling of None inline.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 01 Jun 2017 22:24:15 +0900
parents 548478efc46c
children a05f3675c46a
line wrap: on
line diff
--- a/mercurial/pycompat.py	Thu Jun 01 01:41:34 2017 +0530
+++ b/mercurial/pycompat.py	Thu Jun 01 22:24:15 2017 +0900
@@ -177,6 +177,14 @@
         """Raise exception with the given traceback"""
         raise exc.with_traceback(tb)
 
+    def getdoc(obj):
+        """Get docstring as bytes; may be None so gettext() won't confuse it
+        with _('')"""
+        doc = getattr(obj, u'__doc__', None)
+        if doc is None:
+            return doc
+        return sysbytes(doc)
+
     def _wrapattrfunc(f):
         @functools.wraps(f)
         def w(object, name, *args):
@@ -255,6 +263,9 @@
     # better not to touch Python 2 part as it's already working fine.
     fsdecode = identity
 
+    def getdoc(obj):
+        return getattr(obj, '__doc__', None)
+
     def getoptb(args, shortlist, namelist):
         return getopt.getopt(args, shortlist, namelist)