Skip to content

Commit

Permalink
Rename Null to None in jinja (#1504)
Browse files Browse the repository at this point in the history
<!-- ELLIPSIS_HIDDEN -->


> [!IMPORTANT]
> Renames `Null` to `None` in Jinja templates and updates related logic
and tests.
> 
>   - **Behavior**:
> - Renames `Null` to `None` in Jinja templates in
`jinja-runtime/src/lib.rs` and `jinja/src/evaluate_type/stmt.rs`.
> - Updates logic in `predicate_implications()` to handle `None` instead
of `Null`.
>   - **Tests**:
> - Updates test functions `render_with_ne_none` and
`test_type_narrowing_ne_none` to reflect the change from `Null` to
`None`.
> - Ensures all relevant test cases check for `None` instead of `Null`.
> 
> <sup>This description was created by </sup>[<img alt="Ellipsis"
src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup>
for e007e3c. It will automatically
update as commits are pushed.</sup>


<!-- ELLIPSIS_HIDDEN -->
  • Loading branch information
imalsogreg authored Feb 22, 2025
1 parent b8e3423 commit f42567d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions engine/baml-lib/jinja-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2176,10 +2176,10 @@ mod render_tests {
}

#[test]
fn render_with_ne_null() {
fn render_with_ne_none() {
let result = render_minijinja(
r#"
{% if inp != Null %}
{% if inp != None %}
{{ inp.name }}
{% endif %}
"#,
Expand Down
12 changes: 6 additions & 6 deletions engine/baml-lib/jinja/src/evaluate_type/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use minijinja::machinery::ast::{self, Spanned, Stmt, UnaryOpKind, Var};
use minijinja::machinery::ast::{self, Spanned, Stmt, UnaryOpKind};

use crate::evaluate_type::types::Type;

Expand Down Expand Up @@ -201,8 +201,8 @@ pub fn predicate_implications<'a>(

ast::BinOpKind::Ne => {
let maybe_non_null_variable = match (&binary_op.left, &binary_op.right) {
(Var { .. }, Var(n)) if fuzzy_null(&n) => Some(&binary_op.left),
(Var(n), Var { .. }) if fuzzy_null(&n) => Some(&binary_op.right),
(Var { .. }, Const(n)) if fuzzy_null(&n) => Some(&binary_op.left),
(Const(n), Var { .. }) if fuzzy_null(&n) => Some(&binary_op.right),
_ => None,
};
if let Some(non_null_variable) = maybe_non_null_variable {
Expand All @@ -217,9 +217,9 @@ pub fn predicate_implications<'a>(
}
}

/// Whether an identifier is `Null` or `null`.
fn fuzzy_null(t: &Spanned<Var>) -> bool {
t.id.eq_ignore_ascii_case("null")
/// Whether an identifier is `None` or `none`.
fn fuzzy_null(t: &Spanned<ast::Const>) -> bool {
t.value.to_string().as_str().to_lowercase() == "none"
}

/// Type-narrowing by truthiness. The truthy version of a value's
Expand Down
4 changes: 2 additions & 2 deletions engine/baml-lib/jinja/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ mod tests {
}

#[test]
fn test_type_narrowing_ne_null() {
fn test_type_narrowing_ne_none() {
let mut types = mk_params();
validate_template(
"test",
r#"
{% if foo!=null %}
{% if foo!=none %}
{{ foo.name }}
{% endif %}
"#,
Expand Down

0 comments on commit f42567d

Please sign in to comment.