Patchwork [1,of,4] i18n: use inspect.getsourcelines() to obtain lineno from func or class

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 6, 2016, 4:50 a.m.
Message ID <3fecd4930de102d4151e.1470459012@mimosa>
Download mbox | patch
Permalink /patch/16148/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 6, 2016, 4:50 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1469623994 -32400
#      Wed Jul 27 21:53:14 2016 +0900
# Node ID 3fecd4930de102d4151e4180f85c276145d33c9c
# Parent  2dd8c225e94c19d03713458bbeacc71c30347c51
i18n: use inspect.getsourcelines() to obtain lineno from func or class

Before, func must be a function object. I want to make it parse docstring
of classes, too.

Patch

diff --git a/i18n/hggettext b/i18n/hggettext
--- a/i18n/hggettext
+++ b/i18n/hggettext
@@ -114,7 +114,7 @@  def docstrings(path):
         if func.__doc__:
             src = inspect.getsource(func)
             name = "%s.%s" % (path, func.__name__)
-            lineno = func.func_code.co_firstlineno
+            lineno = inspect.getsourcelines(func)[1]
             doc = func.__doc__
             if rstrip:
                 doc = doc.rstrip()