aboutsummaryrefslogtreecommitdiff
path: root/tests/pattern/composition.test.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-07-01 17:50:29 +0530
committerGitHub <[email protected]>2026-07-01 17:50:29 +0530
commitc757ea1fea447df3ed69e74b407ca9710a9f85e0 (patch)
treea710f73b1a8b7b0117f41a18c9accd01127b033e /tests/pattern/composition.test.py
parentad4eb75ddcadf263391bba8eed837cce3b860cf9 (diff)
parente0d5e70a0d1a35a1e9311aa8200fb5c5f2ca0854 (diff)
downloadedify-c757ea1fea447df3ed69e74b407ca9710a9f85e0.tar.xz
edify-c757ea1fea447df3ed69e74b407ca9710a9f85e0.zip
feat!: Regex result wrapper on .to_regex(), plus flag kwargs at the terminal (#270)
Reshapes what `.to_regex()` returns and takes, so pattern compilation becomes a first-class edify value. ## `Regex` result wrapper class `edify.Regex` is a composition wrapper over `re.Pattern` (which is a CPython C type and cannot be subclassed). It exposes: - `.source` — the emitted regex string. - `.compiled` — the underlying `re.Pattern` for callers that need identity checks, `isinstance` checks, or direct interop with libraries typed on `re.Pattern`. - Eight direct delegates — `.match()`, `.search()`, `.fullmatch()`, `.findall()`, `.finditer()`, `.sub()`, `.subn()`, `.split()` — mirroring the `re.Pattern` query surface. - Value equality on `(source, flags)` plus `__hash__`. ## `to_regex()` now returns `Regex` The terminal returns `edify.Regex` instead of raw `re.Pattern`. The existing eight query methods continue to work via delegation. `.match()` / `.search()` / … on builders (via `MatcherMixin`) still work because they go through the same delegation. **Breaking:** `isinstance(x, re.Pattern)` and `re.Pattern`-typed annotations on values returned from `.to_regex()` break. Callers that need the raw pattern read `.compiled`. ## Flag kwargs on `.to_regex(...)` `.to_regex()` now accepts six keyword-only flag arguments — `ascii_only`, `debug`, `ignore_case`, `multiline`, `dotall`, `verbose` — that OR-merge into the flag snapshot the builder already carries. Passing `ignore_case=True` at the terminal is equivalent to calling `.ignore_case()` mid-chain. Kwargs never turn a chain-set flag off; the terminal is the natural home for pattern-global settings. ## Example ```python from edify import RegexBuilder email = RegexBuilder().start_of_input().one_or_more().letter().end_of_input() regex = email.to_regex(ignore_case=True) regex.source # ^[a-zA-Z]+$ regex.match("Hello") # <re.Match ...> regex.compiled # <re.Pattern object; flags=re.IGNORECASE> ``` Closes #133 Closes #134 Closes #128
Diffstat (limited to 'tests/pattern/composition.test.py')
-rw-r--r--tests/pattern/composition.test.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/tests/pattern/composition.test.py b/tests/pattern/composition.test.py
index f58df57..18a6bc2 100644
--- a/tests/pattern/composition.test.py
+++ b/tests/pattern/composition.test.py
@@ -20,7 +20,7 @@ def test_pattern_exposes_to_regex_string_terminal():
def test_pattern_exposes_to_regex_terminal():
pattern = Pattern().digit()
compiled = pattern.to_regex()
- assert compiled.pattern == "\\d"
+ assert compiled.source == "\\d"
def test_pattern_supports_nested_use_composition():