Skip to content

Commit

Permalink
Use pattern.match(...) instead of re.match(pattern, ...) in `Rege…
Browse files Browse the repository at this point in the history
…xPredicate` and `EmailPredicate` (#42)

* .match method

* changelog

* capitalize

* punct
  • Loading branch information
keithasaurus committed Apr 9, 2024
1 parent 0703958 commit e87258a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
4.1.1 (Apr 9, 2024)
**Optimization**
- Use `pattern.match(...)` instead of `re.match(pattern, ...)` in `RegexPredicate` and `EmailPredicate`

4.1.0 (Feb 29, 2024)
**Features**
- `ValidationResult.map()` can be used to succinctly convert data contained within `Valid` objects to some other type or value
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
project = "Koda Validate"
copyright = "2023, Keith Philpott"
author = "Keith Philpott"
release = "4.1.0"
release = "4.1.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 2 additions & 2 deletions koda_validate/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ class RegexPredicate(Predicate[str]):
pattern: Pattern[str]

def __call__(self, val: str) -> bool:
return re.match(self.pattern, val) is not None
return self.pattern.match(val) is not None


@dataclass
class EmailPredicate(Predicate[str]):
pattern: Pattern[str] = re.compile("[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+")

def __call__(self, val: str) -> bool:
return re.match(self.pattern, val) is not None
return self.pattern.match(val) is not None
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "koda-validate"
version = "4.1.0"
version = "4.1.1"
readme = "README.md"
description = "Typesafe, composable validation"
documentation = "https://koda-validate.readthedocs.io/en/stable/"
Expand Down

0 comments on commit e87258a

Please sign in to comment.