Patchwork [1,of,6] i18n: make hggettext use original docstring to compute offset

mail settings
Submitter Katsunori FUJIWARA
Date Aug. 15, 2017, 4:19 p.m.
Message ID <17bdacaa47c5b08ebe4e.1502813941@speaknoevil>
Download mbox | patch
Permalink /patch/23018/
State Accepted
Headers show


Katsunori FUJIWARA - Aug. 15, 2017, 4:19 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# Date 1501603400 -32400
#      Wed Aug 02 01:03:20 2017 +0900
# Node ID 17bdacaa47c5b08ebe4e5b8e140b9c0f6d4bf129
# Parent  05264fc9d8d64159ab942c1bde400238f2c0ec88
# Available At
#              hg pull -r 17bdacaa47c5
# EXP-Topic i18n-fix-update-pot-issues
i18n: make hggettext use original docstring to compute offset

Before this patch, hggettext uses __doc__ of each functions to compute
offset of document text.

But __doc__ of many functions is already modified by decorators in
registrar (e.g. @templatekeyword adds ":NAME: " prefix to it), and
hggettext can not find it out in original source.

This causes many "unknown offset in ..." warning at "make update-pot",
and leaving them might cause overlooking serious problems.

This patch makes hggettext use original docstring, which decorators in
registrar save into _origdoc, to compute offset.

Even after this patch, there are still a few "unknown offset in ..."
warning at "make update-pot" for specific reasons. These will be fixed
later one by one.


diff --git a/i18n/hggettext b/i18n/hggettext
--- a/i18n/hggettext
+++ b/i18n/hggettext
@@ -122,9 +122,14 @@  def docstrings(path):
             name = "%s.%s" % (actualpath, func.__name__)
             lineno = inspect.getsourcelines(func)[1]
             doc = func.__doc__
+            origdoc = getattr(func, '_origdoc', '')
             if rstrip:
                 doc = doc.rstrip()
-            lineno += offset(src, doc, name, 1)
+                origdoc = origdoc.rstrip()
+            if origdoc:
+                lineno += offset(src, origdoc, name, 1)
+            else:
+                lineno += offset(src, doc, name, 1)
             print(poentry(actualpath, lineno, doc))