* added anystr_lower field to config
* updated docs with any anystr_lower config property
* updated changes folder with markdown describing new change
* added anystr to _validators list under bytes type
* added unit tests for anystr_lower config
* Update pydantic/validators.py
Fix wrong method used in cosntr_lower
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added lower_str to conbytes and constr functions
* Update changes/2134-tayoogunbiyi.md
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* renamed conbytes & constr paramater name
* updated change markdown
* added docs for args to constr and conbytes
* added examples to showing to_lower functionality in conbytes & constr
* added better description for curtail_length
* removed unessary whitespace, added default and types in docs
* Update changes/2134-tayoogunbiyi.md
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* added single whitespace to arguments list under constr & conbytes
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* feat: add validator for NoneType
closes#2095
* feat: support NoneType directly as type
* chore: add change file
* chore: fix typo
* fix: handle Literal[None] for python3.6/3.7 without typing_extensions
* chore: move NotNoneError and export it
* chore: use constant NONE_TYPES to simplify a bit
* chore: use check on Literal instead of typing_extensions
These tests would not run on python 3.8+ without typing_extensions
even though Literal is defined
* test: use fresh Literal[None] in test case
* feat: handle `None` type in schema
* docs: add NoneType documentation
* refactor: switch NONE_TYPES from tuple to set
* Added StrictBytes type
* updated tests for StrictBytes, updated relevant sections in documentation for StrictBytes and ConstrainedBytes
* added changelog
* chore: typo in change
Co-authored-by: Eric Jolibois <em.jolibois@gmail.com>
* Add ability to use min_length/max_length constraints with secret types
* Add change file
* Remove StrLike and BytestLike classes
* Add ability to define constraints for a custom class
* Fix issue with incorrect secrets schema generation
* Add schema test for SecretStr and SecretBytes
* Add test to cover valid secret length
* feat(field): add Enum type support
closes#1735
* test: add extra cases and rename to be more explicit
* refactor: rename enum_validator
* feat: add Enum and IntEnum types support
* docs: add new types
* chore: update change message
* Fix master
* Fix master 2 (#1694)
* test: add regression test with wrong type default
* fix: remove always on conlist and conset
* fix: use utf8 as default encoding on all OS
* conset invalid defualt test
* add change
Co-authored-by: PrettyWood <em.jolibois@gmail.com>
* make secret types idempotent
* remove idempotent from secret types example.
add note to docs for idempotently creating secret types.
use isinstance for comparing when creating secret types idempotently.
add assert for idempotent secret types test.
* tweaks
Co-authored-by: Lasse Gravesen <lasse.gravesen@falcon.io>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
* Change str_validator() return type to str
* Make pattern_validator() accept pre-compiled Pattern objects.
Resolves#1237.
* fix str_validator return type
Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
* ✨ Implement support for infinite generators with Iterable
* ✅ Add tests for infinite generators
* 🎨 Fix format
* 📝 Add docs for infinite generators
* 📝 Add changes file
* ✨ Store sub_field with original type parameter to allow custom validation
* 📝 Add example for validating first value in infinite generators
* 🔥 Remove unused import in example
* ✅ Add test for infinite generator with first-value validation
* ♻️ Update fields with code review
* 📝 Update example from code review
* 📝 Update docs and format from code review
* Trick Cython into allowing str subclassing
* Added a changes file
* Removed 2nd paragraph from changes file so it passes tests
* Augmented with tests for StrictInt/Float
* Removed commented out StrictBool subclass testing
* fix(validate-assignment): do not validate extra fields when `vaidate_assignment` is on
* Update history
* Fix `value` vs. `value_`
* Add tests for `value` vs `value_` case
* uprev
* Fix generic required (#742)
* Fix required fields on GenericModel
* lint
* version up
* __post_init__ with inheritance, fix#739 (#740)
* Fix custom Schema on GenericModel fields (#754)
* Fix custom Schema on GenericModel fields
* Add PR#
* uprev
* Fix error messages for Literal types with multiple allowed values (#770)
* Fix error messages for Literal types with multiple allowed values
* Incorporate feedback
* update history
* big performance improvement!
* exception performance improvement
* check errors and explicit export from errors.py
* more tweaks
* fix coverage
* fix tests and remove "from e" in exceptions for performance
* Added generic approach to strict type checking for constraint types
- Use the arbitrary validator to build strict validators for ConstrainedInt, ConstrainedFloat, ConstrainedStr
- Make StrictStr a derived class of ConstrainedStr
- Add tests for new strict cases for ConstrainedInt and ConstrainedFloat
* - Created StrictInt and StrictFloat subclasses and exported them
- Changed strictness tests to use these new subclasses
* - Added section for Strict Types to docs
* - Added changes file
* Update docs/index.rst
Co-Authored-By: Zaar Hai <haizaar@users.noreply.github.com>
* Update docs/index.rst
Co-Authored-By: Zaar Hai <haizaar@users.noreply.github.com>
* - Create validators for strict int and float
- Make ConstrainedInt and ConstrainedFloat use those validators instead of abusing arbitrary type validator for strictness
- Prevent double validaton of same conditions by only yielding either the strict or non-strict type validator for for those classes
* Changed strict int and float tests to alos match for exception message in invalid cases
* - Removed obvious note about lack of ConstrainedBool
- Added example for strict type usage
- Added note about caveats for StrictInt and StrictFloat
* Update pydantic/validators.py
faster method to check if a value is boolean for strict int validator
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* - Removed StrictBool part from Boolean section of docs
- Moved the Strctbool code example into strict_types.py example file
* - Changed behavior of strictness for COnstrainedStr to match that fo other constrained types
* - Actually make ConstrainedStr use the correct validator for strictness
* Test local and global part of EmailStr validation return values
* Make local part of email case-sensitive per RFC 5321
* Update changes/798-henriklindgren.rst
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* remove case-sensitive specific tests from EmailStr
* new URL parsing, fix#603, fix#541
* AnyUrl parts and more tests
* more coverage and db DSNs
* remove DSN methods
* tests for urlstr
* remove debug
* make AnyStr a subtype of str
* fix with cython
* rearranging networking code
* allowing international domains, cleanup
* support international domains
* better URL builder
* allow underscores in subdomains and domains
* tests for json and schema, max length
* urlstr > stricturl
* updating docs
* tweak docs examples
* tweak docs
* Better error for unsuported "typing" objects.
Fixes#745
Add a better error message for fields with types from the typing
module that are not directly supported by Pydantic. Previously,
it caused a cryptic assertion failure.
* Add support for frozenset fields.
Also provide an example of their usage.
Fixes#745
* Address review comments.
Fixes#745
* use equals not "is" for int comparison.
* Make schema work for Literal and NewType, fix#646
* Fix test when typing_extensions not installed
* Make literal values fetching 3.6 compatible
* Rework to get around issues with Literal in python 3.6
* Make cython-compatible
* Use union for multiple allowed literal values
* Minor simplification of values-gathering
* Updated history
fix#561
* Add support for Literal annotation
* Updated requirements.txt
* incorporating feedback
* skip typing_extensions tests if not installed
* missed a spot
* address feedback
* Make work with python 3.6
* Work for *both* 3.6 and 3.7
* incorporate feedback
* fixed naming and quotes
* Trying to fix LGTM bot issue
* StrictBool
StrictBool only allows booleans to be parsed. Any other value, no matter
its truthiness, is rejected.
* Fix type of `validate`
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
* " => '
* Update the exotic docs with StrictBool
* Fix error message
* Improve docs
* tweak docs.
* Fix issue with unspecified generic type, fix#550
Seems to solve #550
With this change, models with bare `List` or `Dict` as a typehint still validate for type agreement, but don't validate the type of the parameters.
I'm not sure this is the "right" fix (I don't know the implications of ignoring TypeVars like this), but considering how simple it was I figured I'd at least share.
* Update validators.py
Found this discussion: https://github.com/samuelcolvin/pydantic/issues/545; `lenient_issubclass` does seem to fix it.
* Update validators.py
Hacky solution to prevent no validator exception. Maybe there's a better way?
* Tests pass and PR checklist done
* Check sooner
* Block empty list from dict constructor
* Removed modifications to dict_validator