From c8d5a00c1312f5e3668c9756141c5ae4abf5b5da Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Mon, 20 Jul 2026 19:27:35 +0200 Subject: [PATCH 1/2] fix: fix typing for parameter `term` in `parse` and `is_valid_syntax` Signed-off-by: Jan Kowalleck --- src/rfc3987_syntax2/syntax_helpers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/rfc3987_syntax2/syntax_helpers.py b/src/rfc3987_syntax2/syntax_helpers.py index 8592598..dc51199 100644 --- a/src/rfc3987_syntax2/syntax_helpers.py +++ b/src/rfc3987_syntax2/syntax_helpers.py @@ -4,7 +4,7 @@ from pathlib import Path from threading import Lock -from typing import Any, Callable, Optional, TYPE_CHECKING +from typing import Any, Callable, Optional, TYPE_CHECKING, Literal from lark import Lark, ParseTree, exceptions @@ -110,11 +110,14 @@ "pct_encoded", ] -def parse(term: str, value: str) -> 'ParseTree': +_SYNTAX_PARSER_STARTS = ["iri", "iri_reference", "absolute_iri"] +_SYNTAX_PARSER_TERM = Literal["iri", "iri_reference", "absolute_iri"] + +def parse(term: _SYNTAX_PARSER_TERM, value: str) -> 'ParseTree': return _get_syntax_parser().parse(value, start=term) -def is_valid_syntax(term: str, value: str) -> bool: +def is_valid_syntax(term: _SYNTAX_PARSER_TERM, value: str) -> bool: try: parse(term=term, value=value) return True @@ -167,7 +170,7 @@ def _get_syntax_parser() -> Lark: with _syntax_parser_lock: if _syntax_parser is None: _syntax_parser = Lark(grammar, - start=["iri", "iri_reference", "absolute_iri"], + start=_SYNTAX_PARSER_STARTS, parser=RFC3987_SYNTAX_PARSER_TYPE) return _syntax_parser From df5173e3454ee7e7e14e2f2b13e8c2ff7fb0e180 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Mon, 20 Jul 2026 19:31:26 +0200 Subject: [PATCH 2/2] docs Signed-off-by: Jan Kowalleck --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ae7d26..e10efcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ All notable changes to this project will be documented in this file. * Fix `RFC3987_SYNTAX_TERMS` correctly containing "ipath_rootless" (via [#41]) * Fix `RFC3987_SYNTAX_TERMS` correctly containing "ipath_empty" (via [#41]) * Fix `ucschar` range (via [#45]) + * Fix `parse()`'s typehint for arg `term` (via [#50]) + Narrowed down to valid values: "iri", "iri_reference", "absolute_iri" + * Fix `is_valid_syntax`'s typehint for arg `term` (via [#50]) + Narrowed down to valid values: "iri", "iri_reference", "absolute_iri" * Added * Function `is_valid_syntax_scheme` (via [#48]) * Function `is_valid_syntax_non_zero` (via [#48]) @@ -28,6 +32,7 @@ All notable changes to this project will be documented in this file. [#45]: https://github.com/jkowalleck/rfc3987-syntax2/pull/45 [#48]: https://github.com/jkowalleck/rfc3987-syntax2/pull/48 [#49]: https://github.com/jkowalleck/rfc3987-syntax2/pull/49 +[#50]: https://github.com/jkowalleck/rfc3987-syntax2/pull/50 ## v1.2.0 - 2026-07-16