There are a handful of different undefined behaviors that can be opted into in Jinja2. MiniJinja only supports the default. They look roughly like this:
Undefined
value.missing_attr -> undefined
undefined.missing_attr -> err!
for item in undefined -> []
{{ undefined }} -> ""
ChainableUndefined
value.missing_attr -> undefined
undefined.missing_attr -> undefined
for item in undefined -> []
{{ undefined }} -> ""
StrictUndefined
value.missing_attr -> err!
undefined.missing_attr -> err!
for item in undefined -> err!
{{ undefined }} -> err!
The way this is implemented in Jinja2 is by creating different instances of the undefined value in the different parts of the engine. It's also possible to have different types of undefined values flying around. This makes not a lot of sense in MiniJinja since we don't always have the environment available where an undefined value is created.
One option would be to have an UndefinedBehavior enum with the following values:
These would map to the behavior above. Operations on Value that are exported via the API would behave like they do today, but the vm would special case undefined behavior as instructed. Likewise env.format would emit an error in strict mode, and so would the for loop or filters like sort or list.
There are a handful of different undefined behaviors that can be opted into in Jinja2. MiniJinja only supports the default. They look roughly like this:
Undefined
value.missing_attr
->undefined
undefined.missing_attr
-> err!for item in undefined
->[]
{{ undefined }}
->""
ChainableUndefined
value.missing_attr
->undefined
undefined.missing_attr
->undefined
for item in undefined
->[]
{{ undefined }}
->""
StrictUndefined
value.missing_attr
-> err!undefined.missing_attr
-> err!for item in undefined
-> err!{{ undefined }}
-> err!The way this is implemented in Jinja2 is by creating different instances of the undefined value in the different parts of the engine. It's also possible to have different types of undefined values flying around. This makes not a lot of sense in MiniJinja since we don't always have the environment available where an undefined value is created.
One option would be to have an
UndefinedBehavior
enum with the following values:These would map to the behavior above. Operations on
Value
that are exported via the API would behave like they do today, but the vm would special case undefined behavior as instructed. Likewiseenv.format
would emit an error in strict mode, and so would thefor
loop or filters likesort
orlist
.Refs #215 and https://github.com/pallets/jinja/issues/1820