[PATCH 7 of 8] py3: handle unicode docstrings in registrar.py

Pulkit Goyal 7895pulkit at gmail.com
Sun Aug 7 15:54:40 EDT 2016


# HG changeset patch
# User Pulkit Goyal <7895pulkit at gmail.com>
# Date 1470168548 -19800
#      Wed Aug 03 01:39:08 2016 +0530
# Node ID a77a7f6e8bfc90901d829257a782ff11e2bae0f7
# Parent  da4a0ba184d3eff2819d73884770d342edce88c1
py3: handle unicode docstrings in registrar.py

The module importer on Python 3 doesn't rewrite docstrings to bytes
literals. So we need to teach document formatting to convert the
documentation to bytes before formatting to ensure consistent
types are used and the result in bytes.

diff --git a/mercurial/registrar.py b/mercurial/registrar.py
--- a/mercurial/registrar.py
+++ b/mercurial/registrar.py
@@ -83,6 +83,10 @@
 
         'doc' is '__doc__.strip()' of the registered function.
         """
+        # docstrings are using the source file encoding, which should be
+        # utf-8.
+        if not isinstance(doc, bytes):
+            doc = doc.encode(u'utf-8')
         return self._docformat % (decl, doc)
 
     def _extrasetup(self, name, func):


More information about the Mercurial-devel mailing list