Can't compile non template nodes
Package:
pipenv
22232

Exception Class:
TypeError
Raise code
def generate(
node, environment, name, filename, stream=None, defer_init=False, optimized=True
):
"""Generate the python source for a node tree."""
if not isinstance(node, nodes.Template):
raise TypeError("Can't compile non template nodes")
generator = environment.code_generator_class(
environment, name, filename, stream, defer_init, optimized
)
generator.visit(node)
if stream is None:
return generator.stream.getvalue()
Links to the raise (1)
https://github.com/pypa/pipenv/blob/e7fb099e659a7fe661f0be9d4b1d05b681b6d562/pipenv/vendor/jinja2/compiler.py#L83Ways to fix
Error code:
from pipenv.vendor.jinja2.environment import Environment
from jinja2 import Template
#Create template
template = Template('Hello {{ name }}!')
#Create environment
env = Environment()
#Compile template
comp = env.compile(template)
print(comp)
Environment
is the core component of Jinja. It contains important shared variables like configuration, filters, tests, globals, and others. Environment.compile
is used to compile node or template source code. compile
method takes as an argument source which is a Template or string. But in the above code template variable is binary which indicates the location in the memory. That's why an error is raised.
Fix code:
from pipenv.vendor.jinja2.environment import Environment
from jinja2 import Template
#Create template
template = Template('Hello {{ name }}!')
#Render template so variable an become string
an = template.render(name='John Doe')
#Create environment
env = Environment()
#Compile template
comp = env.compile(an)
print(comp)
Add a possible fix
Please authorize to post fix