# HG changeset patch # User FUJIWARA Katsunori # Date 1502605216 -32400 # Node ID 726dd73df3b9e92dc88543772bcb4ac1db291a7e # Parent 1775f93da25c221c1746e367217482396ddc2ccb 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 update-pot". 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 templatefilters.py 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 -r 1775f93da25c -r 726dd73df3b9 i18n/hggettext --- a/i18n/hggettext Wed Aug 02 01:15:07 2017 +0900 +++ b/i18n/hggettext Sun Aug 13 15:20:16 2017 +0900 @@ -24,6 +24,7 @@ import inspect import os +import re import sys @@ -60,9 +61,15 @@ '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 = doctestre.search(doc) + if m: + doc = doc[:m.start()] + # Backslashes in doc appear doubled in src. end = src.find(doc.replace('\\', '\\\\')) if end == -1: