Skip to content

[BUG] Parsing a Python module with EOL escape but no continuation fails #186

@webknjaz

Description

@webknjaz
Traceback (most recent call last):
  File "./migrate.py", line 657, in <module>
    main()
  File "./migrate.py", line 650, in main
    assemble_collections(spec, args)
  File "./migrate.py", line 422, in assemble_collections
    plugin_data_new, import_dependencies = rewrite_imports(plugin_data_new, collection, spec, args.namespace)
  File "./migrate.py", line 237, in rewrite_imports
    mod_fst = redbaron.RedBaron(mod_src_text)
  File "/home/bcoca/work/venvs/build_collection/lib/python3.7/site-packages/redbaron/redbaron.py", line 36, in __init__
    self.node_list = base_nodes.NodeList.from_fst(baron.parse(source_code), parent=self, on_attribute="root")
  File "/home/bcoca/work/venvs/build_collection/lib/python3.7/site-packages/baron/baron.py", line 66, in parse
    return _parse(tokens, print_function)
  File "/home/bcoca/work/venvs/build_collection/lib/python3.7/site-packages/baron/baron.py", line 24, in _parse
    return parser(tokens)
  File "/home/bcoca/work/venvs/build_collection/lib/python3.7/site-packages/baron/grammator.py", line 828, in parse
    return parser.parse(iter(tokens))
  File "/home/bcoca/work/venvs/build_collection/lib/python3.7/site-packages/baron/parser.py", line 167, in parse
    raise ParsingError(debug_output)
baron.parser.ParsingError: Error, got an unexpected token SPACE here:

 103
 104     def _execute_module_with_become(self, module_name, module_args, task_vars,
 105 wrap_async, use_task):
 106         orig_become = self._play_context.become
 107         orig_become_method = self._play_context.become_method
 108         orig_become_user = self._play_context.become_user\
 109
 110 <---- here

Place in the module where this happens: https://github.com/ansible/ansible/blob/8b882be/lib/ansible/plugins/action/win_updates.py#L108-L109

I've checked that

sss = 'some str'\
# some comment
print(sss)

and

sss = 'some str'\

print(sss)

works in CPython given that there's no tokens on the next line.

And

sss = 'some str'\
print(sss)

doesn't work (expected).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions