changeset 33818:ed04d7254a91

i18n: use saved object to get actual function information if available To list up available compression types instead of ".. bundlecompressionmarker" in "hg help bundlespec" output, proxy object "docobject" is used, because: - current online help system requires that __doc__ of registered object (maybe, function) is already well formatted in reST syntax - bundletype() method of compressionengine classes is used to list up available compression types, but - __doc__ of bundletype() object (= "instancemethod") is read-only On the other hand, hggettext requires original function object, in order to get document location in source code. Therefore, description of each compression types isn't yet translatable. Even if translatable, translators should make much effort to determine location of original texts in source code. To get actual function information, this patch makes hggettext use function object saved as "_origfunc", if it is available. This patch also changes bundlecompressiontopics() side, in order to explain how these changes work easily. This patch is a part of preparations for making description of each compression types translatable.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 15 Aug 2017 19:27:24 +0900
parents 726dd73df3b9
children d5ef17608159
files i18n/hggettext mercurial/util.py
diffstat 2 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/i18n/hggettext	Sun Aug 13 15:20:16 2017 +0900
+++ b/i18n/hggettext	Tue Aug 15 19:27:24 2017 +0900
@@ -119,6 +119,8 @@
 
     for func, rstrip in functions:
         if func.__doc__:
+            docobj = func # this might be a proxy to provide formatted doc
+            func = getattr(func, '_origfunc', func)
             funcmod = inspect.getmodule(func)
             extra = ''
             if funcmod.__package__ == funcmod.__name__:
@@ -128,8 +130,8 @@
             src = inspect.getsource(func)
             name = "%s.%s" % (actualpath, func.__name__)
             lineno = inspect.getsourcelines(func)[1]
-            doc = func.__doc__
-            origdoc = getattr(func, '_origdoc', '')
+            doc = docobj.__doc__
+            origdoc = getattr(docobj, '_origdoc', '')
             if rstrip:
                 doc = doc.rstrip()
                 origdoc = origdoc.rstrip()
--- a/mercurial/util.py	Sun Aug 13 15:20:16 2017 +0900
+++ b/mercurial/util.py	Tue Aug 15 19:27:24 2017 +0900
@@ -3752,6 +3752,8 @@
 
         value = docobject()
         value.__doc__ = doc
+        value._origdoc = engine.bundletype.__doc__
+        value._origfunc = engine.bundletype
 
         items[bt[0]] = value