From 494b6bca8acefb1a93f94863ba907dd9ff0f5630 Mon Sep 17 00:00:00 2001 From: yogendra-17 Date: Sat, 7 Mar 2026 16:00:32 +0530 Subject: [PATCH 1/2] handle unsupported types --- pyproject.toml | 2 +- src/arx/parser.py | 17 +++++++++++++++-- tests/test_parser_branches.py | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2745151..b4db6eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ readme = "docs/index.md" authors = [ {name = "Ivan Ogasawara", email = "ivan.ogasawara@gmail.com"} ] -license = "Apache Software License 2.0" +license = "Apache-2.0" requires-python = ">=3.10,<4" dependencies = [ "pyyaml >=4", diff --git a/src/arx/parser.py b/src/arx/parser.py index 1060322..dd069bf 100644 --- a/src/arx/parser.py +++ b/src/arx/parser.py @@ -682,8 +682,21 @@ def _default_value_for_type(self, data_type: astx.DataType) -> astx.Expr: return astx.LiteralString("") if isinstance(data_type, astx.NoneType): return astx.LiteralNone() - return astx.LiteralInt32(0) - + if isinstance(data_type, astx.DateTime): + return astx.LiteralDateTime("1970-01-01T00:00:00") + if isinstance(data_type, astx.Timestamp): + return astx.LiteralTimestamp("1970-01-01T00:00:00") + if isinstance(data_type, astx.Date): + return astx.LiteralDate("1970-01-01") + if isinstance(data_type, astx.Time): + return astx.LiteralTime("00:00:00") + + raise ParserException( + f"Parser: No default value defined for type " + f"'{type(data_type).__name__}'. " + f"An explicit initializer is required." + ) + def parse_type(self) -> astx.DataType: """ title: Parse a type annotation. diff --git a/tests/test_parser_branches.py b/tests/test_parser_branches.py index 46a9ceb..d2ebecd 100644 --- a/tests/test_parser_branches.py +++ b/tests/test_parser_branches.py @@ -206,9 +206,23 @@ def test_parse_type_list_and_default_values() -> None: ) assert isinstance( parser._default_value_for_type(astx.DateTime()), - astx.LiteralInt32, + astx.LiteralDateTime + ) + assert isinstance( + parser._default_value_for_type(astx.Timestamp()), + astx.LiteralTimestamp + ) + assert isinstance( + parser._default_value_for_type(astx.Date()), + astx.LiteralDate + ) + assert isinstance( + parser._default_value_for_type(astx.Time()), + astx.LiteralTime ) + with pytest.raises(ParserException): + parser._default_value_for_type(astx.ListType([astx.Int32()])) def test_parse_unary_and_prototype_error_paths() -> None: """ From 3d4aab5733a0f7e99efcdb1da57b2c2fa9af3669 Mon Sep 17 00:00:00 2001 From: yogendra-17 Date: Sun, 8 Mar 2026 21:20:48 +0530 Subject: [PATCH 2/2] fix lint issues --- src/arx/parser.py | 2 +- tests/test_parser_branches.py | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/arx/parser.py b/src/arx/parser.py index dd069bf..46bbfbf 100644 --- a/src/arx/parser.py +++ b/src/arx/parser.py @@ -696,7 +696,7 @@ def _default_value_for_type(self, data_type: astx.DataType) -> astx.Expr: f"'{type(data_type).__name__}'. " f"An explicit initializer is required." ) - + def parse_type(self) -> astx.DataType: """ title: Parse a type annotation. diff --git a/tests/test_parser_branches.py b/tests/test_parser_branches.py index d2ebecd..e621a1d 100644 --- a/tests/test_parser_branches.py +++ b/tests/test_parser_branches.py @@ -205,25 +205,22 @@ def test_parse_type_list_and_default_values() -> None: astx.LiteralNone, ) assert isinstance( - parser._default_value_for_type(astx.DateTime()), - astx.LiteralDateTime + parser._default_value_for_type(astx.DateTime()), astx.LiteralDateTime ) assert isinstance( - parser._default_value_for_type(astx.Timestamp()), - astx.LiteralTimestamp + parser._default_value_for_type(astx.Timestamp()), astx.LiteralTimestamp ) assert isinstance( - parser._default_value_for_type(astx.Date()), - astx.LiteralDate + parser._default_value_for_type(astx.Date()), astx.LiteralDate ) assert isinstance( - parser._default_value_for_type(astx.Time()), - astx.LiteralTime + parser._default_value_for_type(astx.Time()), astx.LiteralTime ) with pytest.raises(ParserException): parser._default_value_for_type(astx.ListType([astx.Int32()])) + def test_parse_unary_and_prototype_error_paths() -> None: """ title: Parse unary expressions and prototype errors.