comparison i18n/hggettext @ 29720:041fecbb588a

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.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 27 Jul 2016 21:53:14 +0900
parents de28dedd1ff1
children 16a175b3681e
comparison
equal deleted inserted replaced
29719:acf27be56d26 29720:041fecbb588a
112 112
113 for func, rstrip in functions: 113 for func, rstrip in functions:
114 if func.__doc__: 114 if func.__doc__:
115 src = inspect.getsource(func) 115 src = inspect.getsource(func)
116 name = "%s.%s" % (path, func.__name__) 116 name = "%s.%s" % (path, func.__name__)
117 lineno = func.func_code.co_firstlineno 117 lineno = inspect.getsourcelines(func)[1]
118 doc = func.__doc__ 118 doc = func.__doc__
119 if rstrip: 119 if rstrip:
120 doc = doc.rstrip() 120 doc = doc.rstrip()
121 lineno += offset(src, doc, name, 1) 121 lineno += offset(src, doc, name, 1)
122 print(poentry(path, lineno, doc)) 122 print(poentry(path, lineno, doc))