Skip to content

Cannot use template variable {{tag}} in routers.jinja2 imports with modular templates #404

@MarcoCap

Description

@MarcoCap

Minimal problem case, if the content of routers.jinja2 is:

from anymodule import {{tag}}

generation will fail with a "list index out of bounds error".

Instead, this:

from anymodule import anything, {{tag}}

will work as expected.

From the trace of the failure, the problem seems to be that imports are checked in order to correctly insert commas, and in the first case a list ends up being empty probably due to the only import being a template variable.

In the following invoked isort code (from the trace), the "just_imports") list ends up being empty, while import string is from anymodule import ending abruptly.

site-packages\isort\parse.py:522

 if "," in import_string.split(just_imports[-1])[-1]:
   trailing_commas.add(import_from)

I'm not sure if this is fixable since it depends on some other libraries' behaviour, but since adding any other name before {{tag}} makes it work, I thought it might have been worth the effort.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions