-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add 17 built-in validators for common use cases #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vilsonrodrigues
merged 12 commits into
msgflux:main
from
vilsonrodrigues:feat/add-validators-phase1
Dec 3, 2025
Merged
feat: add 17 built-in validators for common use cases #36
vilsonrodrigues
merged 12 commits into
msgflux:main
from
vilsonrodrigues:feat/add-validators-phase1
Dec 3, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Complete project structure overview - Common commands and workflows - Release process (always use ./scripts/release.sh) - Architecture details and optimizations - Linting, testing, and CI/CD guides - Troubleshooting tips This file provides context for Claude Code to work more effectively with the project without repeating instructions.
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Implements Pydantic-like validators using msgspec.Meta and custom str subclasses: **Numeric validators (8):** - PositiveInt, NegativeInt, NonNegativeInt, NonPositiveInt - PositiveFloat, NegativeFloat, NonNegativeFloat, NonPositiveFloat **String validators (9):** - EmailStr (RFC 5321 validation) - HttpUrl (HTTP/HTTPS only), AnyUrl (any scheme) - SecretStr (masks sensitive data in repr/str) - PostgresDsn, RedisDsn (connection string validation) - PaymentCardNumber (Luhn algorithm validation + masking) - FilePath, DirectoryPath (filesystem validation) **Implementation:** - Numeric types use msgspec.Meta for native C validation - String types use custom __new__ validation with proper error messages - dec_hook in settings.py for automatic type conversion - Enhanced _preprocess_env_value to handle Annotated types - 71 comprehensive tests (152 total) **Documentation:** - Complete README section with examples and validator table - New example file (06_validators.py) demonstrating all 17 validators - Updated Features section to highlight validators All tests passing ✅ (152/152) Lint clean ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
**Ruff fixes:** - Auto-format all files (3 files reformatted) - Move tempfile import to top of file - Remove unused variables in try/except blocks - Add noqa directive for PLR0915 (too many statements in example main) - Fix import ordering in test_types.py **CodeQL fixes:** - Add nosec comments for fake credentials in examples - Mark example passwords/secrets as test data All 152 tests passing ✅ Lint clean ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Created CodeQL config to exclude examples/ folder from analysis. Example files contain fake credentials for demonstration purposes only. References: - https://github.com/github/codeql/blob/main/.github/codeql/codeql-config.yml - https://stackoverflow.com/questions/74030852/is-there-a-way-to-exclude-files-from-codeql-scanning-on-github 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
/update |
|
ℹ️ Update commands are not supported for PRs from forks. To update your branch, please run these commands locally: git fetch upstream main
git merge upstream/main
git pushOr create a new PR from the same repository. |
Contributor
Author
|
/merge |
|
❌ Failed to merge PR: Resource not accessible by integration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements 17 Pydantic-like validators using msgspec.Meta and custom str subclasses for common validation use cases:
Numeric Validators (8 types)
msgspec.Metafor native C validation (maximum performance)String Validators (9 types)
Implementation Details
Architecture
Annotated[int/float, msgspec.Meta(...)]for constraintsstrsubclasses with__new__validationdec_hookinsettings.pyfor automatic type conversion_preprocess_env_value()to handleAnnotatedtypesKey Features
Testing
Test results: ✅ 152/152 passing
Lint: ✅ Clean
Documentation
Updated Files
Usage Example
Files Changed
src/msgspec_ext/types.py- New file (496 lines) - All validator implementationstests/test_types.py- New file (684 lines) - Comprehensive test suiteexamples/06_validators.py- New file (349 lines) - Usage examplessrc/msgspec_ext/settings.py- Added dec_hook and Annotated type supportsrc/msgspec_ext/__init__.py- Export all validator typesREADME.md- Documentation updatesPerformance Impact
No performance regression - validators only run when explicitly used:
Next Steps (Future PRs)
This is Phase 1 of validators. Potential future enhancements:
🤖 Generated with Claude Code