Open oomsveta opened 2 months ago
https://github.com/python-babel/babel/pull/488 enabled the python extractor to look at nested calls for strings to extract, but the way it does it ignores nested gettext calls when there's more than one level of nesting.
python
This is because scanning sources for nested calls is only done when call_stack is 0: https://github.com/python-babel/babel/blob/f91754b01cb9f32b83aeaa80b74ed10b5dfccb6a/babel/messages/extract.py#L554-L555 call_stack starts at -1, and is incremented each time an opening parenthesis is encountered within a gettext call: https://github.com/python-babel/babel/blob/f91754b01cb9f32b83aeaa80b74ed10b5dfccb6a/babel/messages/extract.py#L526-L534 In the case of a "deeply nested" call (a call with more than one level of nesting), the value of call_stack will be greater than 0, meaning that the part of the code that handles the nested call will never be reached, and the contents of that call won't be exported.
call_stack
Copy-paste this to your python REPL:
from io import BytesIO from babel.messages.extract import extract file = b"""_( "dummy", nested_call( _("deeply nested call") ) )""" list(extract("python", BytesIO(file))) # -> [(4, 'dummy', [], None)]
[(4, 'dummy', [], None)]
"deeply nested call" is missing. Note: the lineno of "dummy" is also wrong, see this other issue.
[(1, 'dummy', [], None), (4, 'deeply nested call', [], None)]
Overview
https://github.com/python-babel/babel/pull/488 enabled the
python
extractor to look at nested calls for strings to extract, but the way it does it ignores nested gettext calls when there's more than one level of nesting.This is because scanning sources for nested calls is only done when
call_stack
is 0: https://github.com/python-babel/babel/blob/f91754b01cb9f32b83aeaa80b74ed10b5dfccb6a/babel/messages/extract.py#L554-L555call_stack
starts at -1, and is incremented each time an opening parenthesis is encountered within a gettext call: https://github.com/python-babel/babel/blob/f91754b01cb9f32b83aeaa80b74ed10b5dfccb6a/babel/messages/extract.py#L526-L534 In the case of a "deeply nested" call (a call with more than one level of nesting), the value ofcall_stack
will be greater than 0, meaning that the part of the code that handles the nested call will never be reached, and the contents of that call won't be exported.Steps to Reproduce
Copy-paste this to your python REPL:
Actual Results
"deeply nested call" is missing. Note: the lineno of "dummy" is also wrong, see this other issue.
Expected Results