Skip to content

Commit 427692f

Browse files
authored
chore: prep v1.3.0 (#63)
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent b3bc712 commit 427692f

10 files changed

Lines changed: 47 additions & 42 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.
66

77
<!-- unreleased things below this line -->
88

9+
## v1.3.0 - 2026-07-21
10+
911
* Fixed
1012
* Fix grammar for `ucschar` character range (via [#45])
1113
* Fix `RFC3987_SYNTAX_TERMS` correctly containing "ipath" (via [#41])
@@ -20,7 +22,6 @@ All notable changes to this project will be documented in this file.
2022
* Added
2123
* Function `is_valid_syntax` issues a warning if an unexpected error occurred (via [#51])
2224
* New function `is_valid_syntax_scheme` (via [#48])
23-
* New function `is_valid_syntax_non_zero` (via [#48])
2425
* New function `is_valid_syntax_pct_encoded` (via [#48])
2526
* New dict `RFC3987_SYNTAX_TERM_VALIDATORS` mapping `RFC3987_SYNTAX_TERMS` to validator function (via [#49])
2627
* Performance

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "rfc3987-syntax2"
7-
version = "1.2.0"
7+
version = "1.3.0"
88
description = "Helper functions to syntactically validate strings according to RFC 3987."
99
readme = "README.md"
1010
requires-python = ">=3.9"

‎src/rfc3987_syntax2/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Re-export of :mod:`.syntax_helpers`
77
"""
88

9-
from typing import Any, TYPE_CHECKING
9+
from typing import TYPE_CHECKING, Any
1010

1111
from . import syntax_helpers as _syntax_helpers
1212

@@ -18,6 +18,7 @@
1818
from .syntax_helpers import *
1919
# cannot simply re-export - need to respect lazy-loading
2020

21+
2122
def __getattr__(name: str) -> Any:
2223
if name in _EXPORTS_SH:
2324
value = getattr(_syntax_helpers, name)

‎src/rfc3987_syntax2/syntax_helpers.py‎

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
from pathlib import Path
66
from threading import Lock
7-
from typing import Any, Callable, Optional, TYPE_CHECKING, Literal
7+
from typing import TYPE_CHECKING, Any, Callable, Literal, Optional
88
from warnings import warn
99

1010
from lark import Lark, ParseTree, exceptions
1111

1212
from .utils import load_grammar
1313

14-
1514
__all__ = [
1615
"RFC3987_SYNTAX_PARSER_TYPE",
1716
"RFC3987_SYNTAX_GRAMMAR_PATH",
@@ -59,7 +58,6 @@
5958
"is_valid_syntax_ipv4address",
6059
"is_valid_syntax_dec_octet",
6160
"is_valid_syntax_digit",
62-
"is_valid_syntax_non_zero",
6361
"is_valid_syntax_unreserved",
6462
"is_valid_syntax_alpha",
6563
"is_valid_syntax_hexdig",
@@ -127,15 +125,15 @@
127125
"""
128126
_SYNTAX_PARSER_STARTS: list[T_SYNTAX_PARSER_TERM] = ["iri", "iri_reference", "absolute_iri"]
129127

128+
130129
def parse(term: T_SYNTAX_PARSER_TERM, value: str) -> ParseTree:
131130
"""Parse text as one of the top-level RFC 3987 syntax terms.
132131
133-
:param term: Start rule used for parsing. Must be one of ``"iri"``,
134-
``"iri_reference"``, or ``"absolute_iri"``.
132+
:param term: Start rule used for parsing.
133+
Must be one of ``"iri"``, ``"iri_reference"``, or ``"absolute_iri"``.
135134
:param value: Input text to parse.
136135
:return: The Lark parse tree for ``value`` under the selected start rule.
137-
:raises lark.exceptions.LarkError: If parser initialization fails or parsing
138-
cannot be completed.
136+
:raises lark.exceptions.LarkError: If parser initialization fails or parsing cannot be completed.
139137
"""
140138

141139
return _get_syntax_parser().parse(value, start=term)
@@ -146,10 +144,11 @@ def is_valid_syntax(term: T_SYNTAX_PARSER_TERM, value: str) -> bool:
146144
147145
This is a boolean convenience wrapper around :func:`parse`.
148146
149-
.. warning:: Emits a ``RuntimeWarning`` (via :func:`warnings.warn`) when a non-``UnexpectedInput`` ``lark.exceptions.LarkError`` occurs.
147+
.. warning:: Emits a ``RuntimeWarning`` (via :func:`warnings.warn`) when a non-``UnexpectedInput``
148+
``lark.exceptions.LarkError`` occurs.
150149
151-
:param term: Start rule used for validation. Must be one of ``"iri"``,
152-
``"iri_reference"``, or ``"absolute_iri"``.
150+
:param term: Start rule used for validation.
151+
Must be one of ``"iri"``, ``"iri_reference"``, or ``"absolute_iri"``.
153152
:param value: Input text to validate.
154153
:return: ``True`` if parsing succeeds; otherwise ``False``.
155154
"""
@@ -163,11 +162,12 @@ def is_valid_syntax(term: T_SYNTAX_PARSER_TERM, value: str) -> bool:
163162
# from Lark internals / initialization (non-UnexpectedInput)
164163
warn("Unexpected LarkError (non-UnexpectedInput) "
165164
f"for term={term!r}: {type(err).__name__}: {err}",
166-
RuntimeWarning,
167-
stacklevel=2)
165+
RuntimeWarning,
166+
stacklevel=2)
168167
return False
169168
return True
170169

170+
171171
T_SYNTAX_VALIDATOR = Callable[[str], bool]
172172
"""Callable validator for one RFC 3987 grammar rule.
173173
@@ -212,6 +212,7 @@ def syntax_validator(text: str) -> bool:
212212
_grammar: Optional[str] = None
213213
_grammar_lock = Lock()
214214

215+
215216
def _get_grammar() -> str:
216217
"""this is private API"""
217218

@@ -225,6 +226,7 @@ def _get_grammar() -> str:
225226
_syntax_parser: Optional[Lark] = None
226227
_syntax_parser_lock = Lock()
227228

229+
228230
def _get_syntax_parser() -> Lark:
229231
"""this is private API"""
230232

@@ -239,6 +241,7 @@ def _get_syntax_parser() -> Lark:
239241
parser=RFC3987_SYNTAX_PARSER_TYPE)
240242
return _syntax_parser
241243

244+
242245
if TYPE_CHECKING:
243246
def is_valid_syntax_iri(text: str) -> bool:
244247
"""Validate that input text conforms to the RFC 3987 ``IRI`` rule."""
@@ -486,19 +489,6 @@ def is_valid_syntax_digit(text: str) -> bool:
486489
else:
487490
is_valid_syntax_digit = make_syntax_validator("digit")
488491

489-
if TYPE_CHECKING:
490-
def is_valid_syntax_non_zero(text: str) -> bool:
491-
"""
492-
Local helper token used in ``dec_octet``.
493-
494-
.. warning::
495-
Deprecated: this is not a stable/public entry point and may be removed
496-
in a future release.
497-
"""
498-
...
499-
else:
500-
is_valid_syntax_non_zero = make_syntax_validator("non_zero")
501-
502492
if TYPE_CHECKING:
503493
def is_valid_syntax_unreserved(text: str) -> bool:
504494
"""Validate that input text conforms to the RFC 3987 ``unreserved`` rule."""
@@ -571,7 +561,8 @@ def is_valid_syntax_pct_encoded(text: str) -> bool:
571561
"ipv4address": is_valid_syntax_ipv4address,
572562
"dec_octet": is_valid_syntax_dec_octet,
573563
"digit": is_valid_syntax_digit,
574-
"non_zero": is_valid_syntax_non_zero,
564+
# non_zero - a local helper token used in `dec_octet`
565+
"non_zero": make_syntax_validator("non_zero"),
575566
"unreserved": is_valid_syntax_unreserved,
576567
"alpha": is_valid_syntax_alpha,
577568
"hexdig": is_valid_syntax_hexdig,
@@ -605,6 +596,7 @@ def __getattr__(name: str) -> Any:
605596
return syntax_parser
606597
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
607598

599+
608600
def __dir__() -> list[str]:
609601
return sorted(set(globals().keys()) | set(__all__))
610602

‎tests/__init__.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import json
66
from pathlib import Path
77
from typing import TypedDict
8-
from typing_extensions import Required, NotRequired
8+
9+
from typing_extensions import NotRequired, Required
910

1011
TESTS_ROOT_DIR = Path(__file__).parent
1112
TESTS_DATA_DIR = TESTS_ROOT_DIR / '_data'
@@ -15,6 +16,7 @@
1516
'valid_syntax': TESTS_DATA_DIR / 'valid_syntax.json',
1617
}
1718

19+
1820
class SyntaxCase(TypedDict):
1921
value: Required[str]
2022
reason: Required[str]
@@ -23,12 +25,15 @@ class SyntaxCase(TypedDict):
2325
conforms_with_rfc3987_semantics: NotRequired[bool]
2426
semantics_notes: NotRequired[str]
2527

28+
2629
T_syntax_file = dict[str, list[SyntaxCase]]
2730

31+
2832
def valid_syntax_data() -> T_syntax_file:
2933
with open(TESTS_DATA_FILES['valid_syntax'], "r", encoding="utf-8") as f:
3034
return json.load(f) # type:ignore[no-any-return]
3135

36+
3237
def invalid_syntax_data() -> T_syntax_file:
3338
with open(TESTS_DATA_FILES['invalid_syntax'], "r", encoding="utf-8") as f:
34-
return json.load(f) # type:ignore[no-any-return]
39+
return json.load(f) # type:ignore[no-any-return]

‎tests/test_exports_exists.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
# SPDX-License-Identifier: MIT
44

55
import rfc3987_syntax2 as sut
6-

‎tests/test_is_valid_syntax_warning.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Copyright (c) 2026 Jan Kowalleck - modifications and maintenance
22
# SPDX-License-Identifier: MIT
33

4-
import pytest
54
from unittest.mock import patch
65

6+
import pytest
77
from lark import exceptions
88

99
import rfc3987_syntax2.syntax_helpers as sut

‎tests/test_lazy_attrs.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
import subprocess
55
import sys
66

7-
import rfc3987_syntax2 as sut
87
from lark import Lark
98

9+
import rfc3987_syntax2 as sut
10+
1011

1112
def test_grammar_not_eager() -> None:
1213
"""Regression test: grammar is not populated in rfc3987_syntax2.__dict__ immediately after import."""
1314
result = subprocess.run(
14-
[sys.executable, '-c', 'import rfc3987_syntax2; assert "grammar" not in vars(rfc3987_syntax2), "grammar was eagerly loaded on import"'],
15+
[sys.executable, '-c',
16+
'import rfc3987_syntax2; assert "grammar" not in vars(rfc3987_syntax2), "grammar was eagerly loaded on import"'],
1517
capture_output=True,
1618
text=True,
1719
)
@@ -21,7 +23,8 @@ def test_grammar_not_eager() -> None:
2123
def test_syntax_parser_not_eager() -> None:
2224
"""Regression test: syntax_parser is not populated in rfc3987_syntax2.__dict__ immediately after import."""
2325
result = subprocess.run(
24-
[sys.executable, '-c', 'import rfc3987_syntax2; assert "syntax_parser" not in vars(rfc3987_syntax2), "syntax_parser was eagerly loaded on import"'],
26+
[sys.executable, '-c',
27+
'import rfc3987_syntax2; assert "syntax_parser" not in vars(rfc3987_syntax2), "syntax_parser was eagerly loaded on import"'],
2528
capture_output=True,
2629
text=True,
2730
)

‎tests/test_syntax.py‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@
88

99
import rfc3987_syntax2 as sut
1010

11-
from . import (
12-
valid_syntax_data,
13-
invalid_syntax_data,
14-
SyntaxCase,
15-
T_syntax_file,
16-
)
11+
from . import SyntaxCase, T_syntax_file, invalid_syntax_data, valid_syntax_data
1712

1813

1914
def syntax_data_as_params(src_cb: Callable[[], T_syntax_file]) -> Any:

‎tests/test_term_validators.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99

1010
@pytest.mark.parametrize("term", sut.RFC3987_SYNTAX_TERMS)
11+
def test_term_validator_exists(term: str) -> None:
12+
actual = sut.RFC3987_SYNTAX_TERM_VALIDATORS.get(term)
13+
assert (actual is not None), f"missing func for {term}"
14+
15+
16+
@pytest.mark.parametrize("term", (t for t in sut.RFC3987_SYNTAX_TERMS if t not in [
17+
# non_zero - a local helper token used in `dec_octet`
18+
'non_zero',
19+
]))
1120
def test_term_validator_as_expected(term: str) -> None:
1221
expected = getattr(sut, f'is_valid_syntax_{term}')
1322
actual = sut.RFC3987_SYNTAX_TERM_VALIDATORS[term]

0 commit comments

Comments
 (0)