Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting messages from py files with f-strings. #108

Open
atom32k opened this issue Dec 7, 2022 · 0 comments
Open

Extracting messages from py files with f-strings. #108

atom32k opened this issue Dec 7, 2022 · 0 comments

Comments

@atom32k
Copy link

atom32k commented Dec 7, 2022

Hi,

Looks like python ast module literal_eval doesn't play well with f-strings in code.

Traceback (most recent call last):
  File "/home/vagrant/venv/bin/pot-create", line 8, in <module>
    sys.exit(main())
  File "/home/vagrant/venv/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/vagrant/venv/lib/python3.8/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/vagrant/venv/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/vagrant/venv/lib/python3.8/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/vagrant/venv/lib/python3.8/site-packages/lingua/extract.py", line 426, in main
    for message in extractor(real_filename, extractor_options):
  File "/home/vagrant/venv/lib/python3.8/site-packages/lingua/extractors/python.py", line 415, in __call__
    return parser(token_stream, options, filename, lineno)
  File "/home/vagrant/venv/lib/python3.8/site-packages/lingua/extractors/python.py", line 188, in __call__
    self.process_token(token_type, token, location, token_stream)
  File "/home/vagrant/venv/lib/python3.8/site-packages/lingua/extractors/python.py", line 216, in process_token
    self.handler(token_type, token, location, token_stream)
  File "/home/vagrant/venv/lib/python3.8/site-packages/lingua/extractors/python.py", line 310, in state_in_keyword_call
    token = safe_eval(token)
  File "/home/vagrant/venv/lib/python3.8/site-packages/lingua/extractors/python.py", line 111, in safe_eval
    return ast.literal_eval(s)
  File "/usr/lib/python3.8/ast.py", line 99, in literal_eval
    return _convert(node_or_string)
  File "/usr/lib/python3.8/ast.py", line 98, in _convert
    return _convert_signed_num(node)
  File "/usr/lib/python3.8/ast.py", line 75, in _convert_signed_num
    return _convert_num(node)
  File "/usr/lib/python3.8/ast.py", line 66, in _convert_num
    _raise_malformed_node(node)
  File "/usr/lib/python3.8/ast.py", line 63, in _raise_malformed_node
    raise ValueError(f'malformed node or string: {node!r}')
ValueError: malformed node or string: <_ast.JoinedStr object at 0x7ffb86797880>

Any workaround for this besides changing f-strings to format() syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant