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

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

Open
MarcoCap opened this issue Jan 19, 2024 · 0 comments

Comments

@MarcoCap
Copy link

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.

@MarcoCap MarcoCap changed the title Cannot use template variable {{tag}} in routers.jinja2 imports Cannot use template variable {{tag}} in routers.jinja2 imports with modular templates Jan 19, 2024
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