Patchwork [3,of,6] i18n: ignore doctest part to avoid warning at "make update-pot"

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


Katsunori FUJIWARA - Aug. 15, 2017, 4:19 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# Date 1502605216 -32400
#      Sun Aug 13 15:20:16 2017 +0900
# Node ID 1d204d17d51eb143f1ef66426cec1831cd8c93bf
# Parent  abd0f3801a00bf7d3e5a74de796ec68d97d3e9dd
# Available At
#              hg pull -r 1d204d17d51e
# EXP-Topic i18n-fix-update-pot-issues
i18n: ignore doctest part to avoid warning at "make update-pot"

hggettext assumes that backslashes in docstring are always doubled in
original source code, in order to find the location of original
docstring out certainly.

This assumption almost always works as expected. But doctest easily
breaks it, because many of backslashes in doctests aren't doubled.
This mismatching causes "unknown offset in ..." warning at "make

To avoid such warning, this patch ignores doctest part of docstring
before finding the location of original docstring out.

BTW, at this patch, only person() in has doctest
part, which causes "unknown offset ..." warning.

Therefore, just making backslashes in that doctest doubled can avoid
such warning, too. But forcing doctest writers to double backslashes
in doctest isn't reasonable, IMHO.


diff --git a/i18n/hggettext b/i18n/hggettext
--- a/i18n/hggettext
+++ b/i18n/hggettext
@@ -24,6 +24,7 @@  from __future__ import absolute_import, 
 import inspect
 import os
+import re
 import sys
@@ -60,9 +61,15 @@  def poentry(path, lineno, s):
             'msgid %s\n' % normalize(s) +
             'msgstr ""\n')
+doctestre = re.compile(r'^ +>>> ', re.MULTILINE)
 def offset(src, doc, name, default):
     """Compute offset or issue a warning on stdout."""
+    # remove doctest part, in order to avoid backslash mismatching
+    m =
+    if m:
+        doc = doc[:m.start()]
     # Backslashes in doc appear doubled in src.
     end = src.find(doc.replace('\\', '\\\\'))
     if end == -1: