From b8e06ac1a3708bb326d20dcdde1879742dc03048 Mon Sep 17 00:00:00 2001 From: David Langerman Date: Wed, 26 Aug 2026 13:15:39 -0400 Subject: [PATCH] fix bug where operators could be in expressions --- dltype/_lib/_parser.py | 11 ++++++++--- dltype/tests/parser_test.py | 5 +++++ pyproject.toml | 2 +- uv.lock | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dltype/_lib/_parser.py b/dltype/_lib/_parser.py index 94f01e9..5f50682 100644 --- a/dltype/_lib/_parser.py +++ b/dltype/_lib/_parser.py @@ -461,9 +461,14 @@ def _tokenize_string_expr( # noqa: C901, PLR0912 assert isinstance(character, str) for op in _DLTypeOperator: if tuple(expression[idx : idx + len(op.value)]) == tuple(op.value): - second_pass_return_list[idx - offset] = op - offset += len(op.value) - 1 - found_operator = True + # we might have an operator, but if the operator is functional we need to check for a ( next + if ( + op not in _functional_operators + or expression[idx + len(op.value)] == _DLTypeGroupToken.LPAREN.value + ): + second_pass_return_list[idx - offset] = op + offset += len(op.value) - 1 + found_operator = True break if not found_operator: for spec in _DLTypeSpecifier: diff --git a/dltype/tests/parser_test.py b/dltype/tests/parser_test.py index 943a6e1..bdc23f5 100644 --- a/dltype/tests/parser_test.py +++ b/dltype/tests/parser_test.py @@ -31,6 +31,7 @@ ("max(3^x,min(3-y,99))", {"x": 2, "y": 4}, 9), ("min(3^x,3-y)", {"x": 2, "y": 4}, -1), ("variable_name_with_underscores", {"variable_name_with_underscores": 1}, 1), + ("max_variable_starts_with_operator", {"max_variable_starts_with_operator": 1}, 1), ("isqrt(5)", {}, 2), ("isqrt(16)", {}, 4), ("isqrt(x-y)", {"x": 20, "y": 5}, 3), @@ -93,6 +94,10 @@ def test_parse_expression( ("min()", {}), ("a=b=2", {}), ("isqrt(*)", {}), + ("+_variable_name", {}), + ("max(", {}), + ("a_max(", {}), + ("a_max()", {}), ("dim+", {}), ("dim%", {}), ("dim?", {}), diff --git a/pyproject.toml b/pyproject.toml index 83d57bc..0e3b2be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ license-files = ["LICENSE"] name = "dltype" readme = "README.md" requires-python = ">=3.10" -version = "0.16.0" +version = "0.17.0" [project.optional-dependencies] jax = ["jax>=0.6.2"] diff --git a/uv.lock b/uv.lock index c53e892..81ec382 100644 --- a/uv.lock +++ b/uv.lock @@ -211,7 +211,7 @@ nvtx = [ [[package]] name = "dltype" -version = "0.16.0" +version = "0.17.0" source = { virtual = "." } dependencies = [ { name = "pydantic" },