From fc3279ca563d52e3b8456a33ce7c85d21389365c Mon Sep 17 00:00:00 2001 From: Almas Akchabayev Date: Sun, 3 Nov 2024 22:42:41 +0300 Subject: [PATCH 1/7] chore: remove uuid from dependencies --- pyproject.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f9f8f96..6e27ab6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,8 +21,7 @@ classifiers = [ ] dependencies = [ "validators>0.28", - "typing_extensions>4.12", - "uuid==1.30" + "typing_extensions>4.12" ] [project.optional-dependencies] From 6792dc64ea2c66d305eddf24bf18eecbbef09bc8 Mon Sep 17 00:00:00 2001 From: Nuno Pereira Date: Thu, 7 Nov 2024 17:26:21 +0100 Subject: [PATCH 2/7] Made CI run on PR. Update contribution guidelines. --- .github/workflows/ci.yaml | 2 +- CHANGELOG.md | 4 ++++ CONTRIBUTING.md | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1bd1d1c..6a9d085 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ name: CI -on: [push] +on: [push, pull_request] jobs: lint: diff --git a/CHANGELOG.md b/CHANGELOG.md index 22ddefc..a283d17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- Updated contribution guidelines. +- Updated CI workflow to run on Pull Request. + ## [2.0.1] - 2024-07-16 ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d356b13..19b4191 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,3 +36,8 @@ Pull requests should be used to propose changes to the codebase. When creating a - **All pull requests** should be tagged with the appropriate labels. If you are unsure about which labels to use, please use the `help wanted` label. - **All pull requests** should (but are not strictly required to) be accompanied by a description of the alternatives considered when making the changes in the pull request. +All changes must be summarized in [CHANGELOG.md](CHANGELOG.md). + +Furthermore, new contributors can add themselves to the list of contributors, present at [CONTRIBUTORS](CONTRIBUTORS). + + From 76b47c3dba170ae632e7d5ab5c3bf056f828ab34 Mon Sep 17 00:00:00 2001 From: cachho Date: Wed, 5 Feb 2025 10:28:35 +0100 Subject: [PATCH 3/7] docs: fix list basic type --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ddfc787..e23d424 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ zon.element_list(zon.string()) Like strings, lists also have some extra methods that check the length of the list: ```python -validator = zon.list(...) +validator = zon.element_list(...) validator.min(5) validator.max(10) @@ -187,7 +187,7 @@ validator = zon.record({ "name": zon.string(), "age": zon.number(), "isAwesome": zon.boolean(), - "friends": zon.array(zon.string()), + "friends": zon.element_list(zon.string()), "address": zon.record({ "street": zon.string(), "city": zon.string(), From 51279d18142309698afc37ded7b256dae3bca6a3 Mon Sep 17 00:00:00 2001 From: cachho Date: Wed, 5 Feb 2025 10:33:38 +0100 Subject: [PATCH 4/7] docs: validate --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index e23d424..3d4640d 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,17 @@ In its essence, `zon` behaves much like `zod`. If you have used `zod`, you will > [!NOTE] > There are some differences in the public API between `zon` and `zod`. Those mostly stem from the fact that Python does not have type inference like Typescript has. There are other slight deviations between `zon` and `zod`. +### General + +#### Validate + +To validate against a schema, use `validator.validate()` + +```python +validator = zon.string() +validator.validate("Hello World!") # returns 'Hello World!' +``` + ### Basic types `zon` features most of `zod`'s basic types: From 3a504e166268e1151768bb820a3900dd1729c89e Mon Sep 17 00:00:00 2001 From: cachho Date: Wed, 5 Feb 2025 23:35:39 +0100 Subject: [PATCH 5/7] docs: safe_validate --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d4640d..99d644d 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,18 @@ To validate against a schema, use `validator.validate()` ```python validator = zon.string() -validator.validate("Hello World!") # returns 'Hello World!' +message = validator.validate("Hello World!") # returns 'Hello World!' ``` +Alternatively, you may use `validator.safe_validate()`. +`save_validate` will tell you whether the validation was successful, without throwing an error. Depending on the needs of your project, you can do this to handle exceptions more elegantly. + +```python +validator = zon.string() +success, message = validator.safe_validate("Hello World!") # returns (True, 'Hello World!') +``` + + ### Basic types `zon` features most of `zod`'s basic types: From 42e8a9e440a2524811aa88a3f56cef32a51ea4eb Mon Sep 17 00:00:00 2001 From: Nuno Pereira Date: Fri, 16 May 2025 19:38:11 +0100 Subject: [PATCH 6/7] Added details about chaining API to Readme --- CHANGELOG.md | 3 +++ README.md | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a283d17..94a7dbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated contribution guidelines. - Updated CI workflow to run on Pull Request. +### Added +- Added explanation about chaining API to README.md. + ## [2.0.1] - 2024-07-16 ### Changed diff --git a/README.md b/README.md index 99d644d..a5f0df1 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,22 @@ validator = zon.string() success, message = validator.safe_validate("Hello World!") # returns (True, 'Hello World!') ``` +#### Chaining + +Most validators can be chained together, just like `zod`: + +```python +validator = zon.string().min(5).max(10).email() +``` + +This is equivalent to: + +```python +validator = zon.string() +validator = validator.min(5) +validator = validator.max(10) +validator = validator.email() +``` ### Basic types From 981009c726065a2ea72d45e7dd6695669b3f7058 Mon Sep 17 00:00:00 2001 From: Nuno Pereira Date: Fri, 16 May 2025 17:35:40 +0100 Subject: [PATCH 7/7] Started preparing 3.0.0 release --- CHANGELOG.md | 11 ++++++++++- CONTRIBUTORS | 4 +++- pyproject.toml | 2 +- zon/__init__.py | 6 ++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94a7dbc..9ab3cef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + ## [Unreleased] +## [3.0.0] - 2025-05-16 + ### Changed - Updated contribution guidelines. - Updated CI workflow to run on Pull Request. +- Updated README.md to include more information and examples of code usage as well as corrected some old examples. +- Added contributors to the CONTRIBUTORS file. + +### Deleted +- Removed `uuid` as a dependency. ### Added - Added explanation about chaining API to README.md. @@ -64,7 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added base source code files for the project. - Base `README.md` file. -[unreleased]: https://github.com/Naapperas/zon/compare/v2.0.1...HEAD +[Unreleased]: https://github.com/Naapperas/zon/compare/v3.0.0...HEAD +[3.0.0]: https://github.com/Naapperas/zon/compare/v2.0.1...v3.0.0 [2.0.1]: https://github.com/Naapperas/zon/compare/v2.0.0...v2.0.1 [2.0.0]: https://github.com/Naapperas/zon/compare/v1.1.0...v2.0.0 [1.1.0]: https://github.com/Naapperas/zon/compare/v1.0.0...v1.1.0 diff --git a/CONTRIBUTORS b/CONTRIBUTORS index b90c860..abf3634 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1 +1,3 @@ -Nuno Pereira \ No newline at end of file +Nuno Pereira +cachho +Almas Akchabayev <> \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 6e27ab6..25fb16a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "zon" -version = "2.0.0" +version = "3.0.0" authors = [ { name="Nuno Pereira", email="nunoafonso2002@gmail.com" }, ] diff --git a/zon/__init__.py b/zon/__init__.py index 4d346c3..4b8e596 100644 --- a/zon/__init__.py +++ b/zon/__init__.py @@ -6,7 +6,7 @@ # Why is this needed even? from __future__ import annotations -__version__ = "2.0.0" +__version__ = "3.0.0" __author__ = "Nuno Pereira" __email__ = "nunoafonso2002@gmail.com" __license__ = "MIT" @@ -181,7 +181,9 @@ def _default_validate(self, data: T, ctx: ValidationContext) -> T: ) @final - def _validate(self, data: T) -> tuple[Literal[True], T] | tuple[Literal[False], ZonError]: + def _validate( + self, data: T + ) -> tuple[Literal[True], T] | tuple[Literal[False], ZonError]: """Validates the supplied data. Args: