Commit Graph

51 Commits

Author SHA1 Message Date
Samuel Colvin bff8a1789d single quotes in tests 2019-04-25 11:54:05 +01:00
jakeb a3d9ad16e7 Fix dict with extra keys (#490)
* Fix dict with extra keys (#489), fix #488

* Fix PR number

* Fix Config of MyModel not to inherit BaseConfig
2019-04-25 11:50:58 +01:00
Samuel Colvin bbbc8987a8 Classvars (#455)
* Support specialized ClassVars, e. g. ClassVar[int] now works in a model, fix #435

* Use apostrophes and pass the test also on python 3.6, where ClassVar[int] is a ClassVar, not a _GenericAlias. Note that the == operator gives False in this case, so we must really compare the classes directly.

* Another attempt at the ClassVar check.

* Ran make format.

* Make mypy happy.

* add HISTORY
2019-04-03 11:58:28 +01:00
Yaraslau Zhylko 37855aa90c fix typo in NoneIsNotAllowedError message (#414)
* fix typo in `NoneIsNotAllowedError` message

* Add HISTORY.rst entry
2019-03-07 13:33:58 +00:00
Daniel Smith 5438aa5c91 Allow autocompletion of fields (#398)
* Allows interactive usage to autocomplete fields

* History add now that PR # is available
2019-02-18 07:53:02 +00:00
Daniel Smith 96e3e74262 Tracking for setting attributes (#389)
fix #378

* Tracking for setting attributes

* Fixes accidental leak of fields

* Allows defaults fields to be recursively set

* Docs and history for skip_defaults

* Mypy fix on calculate keys

* Update pydantic/main.py

Co-Authored-By: dgasmith <dgasmith@icloud.com>

* Update pydantic/main.py

Co-Authored-By: dgasmith <dgasmith@icloud.com>

* Update HISTORY.rst

Co-Authored-By: dgasmith <dgasmith@icloud.com>

* Cleanup pass based off review

* Simplifies constructors based on feedback

* Makes mypy happy with exlicit KeysView

* SetOrKeys and faster key search

* Formats files once more

* add tests for dict, pickle and construct

* fixes for dict, pickle and construct

* correct field_set for extra.ignore

* Fixes format
2019-02-13 15:10:45 +00:00
Or Carmi 9900c7f00c Refactored extra types to use a single enum (#352)
deprecated `ignore_extra` and `allow_extra` Config fields in favor of `extra`, fix #352

* refaactored extra types to use a single enum

* slightly simplified

* added tests

* fixed most stuff

* docs and some simplifications

* better assert

* changed enum and fixed logic

* trying to capture deprecation warning

* make format

* fixing tests and moving exta logic to __new__

* set_extra tests

* fox benchmarks

* formatting

* updated history

* docs

* added a negative tests

* reverted format changes

* format

* matched casing

* renamed values

* more fixes

* forgot values change

* another one

* weird stuff

* linting issue

* Update pydantic/main.py

Co-Authored-By: liiight <4374581+liiight@users.noreply.github.com>
2019-02-04 13:15:07 +00:00
Samuel Colvin c2bae0a05d support ClassVar, (#339)
* support ClassVar, fix #184

* fix tests, update history
2018-12-27 20:44:02 +00:00
Samuel Colvin 9ad1a0ad24 reame get_validators > __get_validators__ (#338)
* reame get_validators > __get_validators__

* update docs
2018-12-27 20:30:41 +00:00
Samuel Colvin 15850a43c5 moving to black (#287)
* moving to black

* put back flake8

* remove isort option

* putting back isort

* uprev pycodestyle

* remove black from docs/examples

* tweak parse.py
2018-11-15 11:30:07 +00:00
Alban Diquet 8885503ccb Raise a NameError if a field name shadows a BaseModel attribute (#243)
* Raise a NameError if a field name shadows a BaseModel attribute fix #242

* Move the test and also check the names of non-annotation attributes

* Fix for flake8

* Fix import order

* Move validate_field_name to utils

* Linting

* Update history
2018-08-05 17:48:40 +01:00
Nikita Grishko 489a1d32b1 add `by_alias argument in .dict() and .json()` model methods (#222)
* add ``by_alias`` argument in ``.dict()`` and ``.json()`` model methods #205

* review fixes

fix #205
2018-07-07 15:06:55 +01:00
Evghenii Goncearov 73015d2a72 Allow arbitrary types in model (#209)
* Allow arbitrary types in model

* Replaced ConfigError with RuntimeError

* Corrections of the ArbitraryTypeError exception class
2018-07-02 12:08:43 +01:00
Samuel Colvin 37364a05b9 implement JSON serialisation (#210)
* implement JSON serialisation, fix #133

* documenting JSON serialisation

* fix coverage
2018-06-28 18:21:45 +01:00
Samuel Colvin dd8d013e10 Schemas (#190)
* starting field and model schemas

* field.schema()

* sub-models working

* move default in Schema and tests

* adding schema

* tweak docs
2018-06-28 13:06:24 +01:00
Samuel Colvin f0f9de5f96 improve docs on error handling (#198)
* improve docs on error handling

* change ValidationError signature

* cleanup

* rename _raw_errors > raw_errors

* improve _display_error_type_and_ctx
2018-06-11 13:06:50 +01:00
Samuel Colvin 2687fae6e9 copy defaults to values, fix #154 (#192) 2018-06-06 16:36:40 +01:00
Samuel Colvin 31f5f9c267 Cleanup 183 (#187)
* fix coverage

* use change_exception

* simplifying get_exc_type

* improve to_snake_case

* improve change_exception

* remove to_snake_case completely

* correct comment
2018-06-02 18:08:07 +01:00
Nikita Grishko 4f4e22ef47 Error context and message (#183)
* POC of error context and message

* Move type errors to the `errors.py` module; Change errors interface a bit

* Rename `.as_dict()` to `.dict()`

* Fix `PydanticErrorMixin` constructor

* Rename `exceptions.py` to `error_wrappers.py`

* Do not include nullable `ctx`

* Fix tests

* Added `int_validator`; Added `IntegerError`

* Added `float_validator`; Added `FloatError`

* Get rid of `__mro__` in prior of `exc.code`

* Removed `min_number_size` and `max_number_size` from config (#174)

* Added `NumberMinSizeError` and `NumberMaxSizeError`

* Added `NoneIsNotAllowedError`

* Added `EnumError`

* Added `path_validator`; Added `PathError`

* Added `DictError`

* Added `ListError`

* Added `TupleError`

* Added `SetError`

* Added `datetime` related errors

* Added `bytes` and `str` related errors

* Added `SequenceError`

* Improved code coverage

* Display error context in string representation of validation error

* Redefine error message templates using config

* Review fixes

* Updated changelog
2018-05-31 14:35:38 +01:00
Ben Demaree 62d39d90a7 Make model dump/load symmetric for aliased fields (#160)
* Make dump/load symmetric for aliased fields

* Only populate model fields by alias if enabled

* Document Config.allow_population_by_alias

* Update history

* Fix doc formatting

* Fix doc errors
2018-05-24 16:46:03 +01:00
Nikita Grishko 31683f8dc4 Errors format (#179)
* Get rid of `track` in errors

* Move `display_as_type` func into utils module

* Get rid of error as `namedtuple`

* Renamed `Error.index` to `Error.loc`

* New way to get error type

* New way to get error message

* New errors format

* Renamed `flatten_errors` property to `flat_errors`

* `__slots__` for `Error` and `ValidationError`

* `loc` as `tuple`

* Tests

* Review fixes

* `flatten_errors` as generator
2018-05-23 14:50:04 +01:00
Samuel Colvin 7a77d06058 add use_enum_values to config (#127)
* add `use_enum_values` to config

* docs and history
2018-02-06 18:23:41 +00:00
Samuel Colvin e3444ba7c2 remove .values() from model 2018-02-06 14:40:13 +00:00
Samuel Colvin 91f962e533 replace values() with dict() (#99)
* replace values(), with dict(), fix #98

* add history and test
2017-11-07 13:28:42 +00:00
petroswork fe8031703b Perform validation on assignment to attribute (#94)
* Perform validation on assignment to attribute

* Add config variable "validate_assignment" defaulting to False.
* Add unit test.

* Add non-empty second parameter to fields.validate

* Improved tests per maintainer's suggestions.

* Improved tests.

* Add documentation in index.rst
2017-10-31 20:04:40 +00:00
Samuel Colvin b10566841e Less verbose errors (#90)
* make errors less verbose, fix #71

* remove track too if null

* update docs

* better dict error, fix #74

* add history
2017-10-23 20:06:48 +01:00
Samuel Colvin 5efa54d80d annotation only fields first 2017-07-08 19:01:38 +01:00
Samuel Colvin 044fd42f4f parser methods (#58), fix #39
* working on parsers

* starting parse tests

* proper tests for parse

* adding parse docs

* tweaks and history

* add test for datetime direct, fix tests

* tweak docs
2017-07-08 18:39:24 +01:00
Samuel Colvin 378c96888e simplifying errors 2017-07-08 18:22:57 +01:00
Samuel Colvin 98d5657406 use unicode ellipsis in truncate 2017-07-08 15:00:35 +01:00
Samuel Colvin 6923e5e677 models allowing immutability (#44)
* working on models allowing immutability, ref #38

* up complexity

* use noqa c901

* fixing fields with new processor

* allow_mutation config and tests

* uprev, history and docs

* fix typos
2017-06-13 09:52:47 +01:00
Samuel Colvin ff3fa95eb0 convert values to a function, fix #28 (#43) 2017-06-07 22:40:09 +01:00
Samuel Colvin 691b947576 add pretty print for models (#42) 2017-06-07 20:34:13 +01:00
Samuel Colvin c81ec9aeec add support for annotation only fields (#41)
* add support for annotation only fields, fix #34

* adding tests with mypy

* adding docs for mypy usage

* adding mypy failure test

* adding alias tests

* tweak mypy tests
2017-06-07 19:56:46 +01:00
Samuel Colvin ea88afb212 allow aliases 2017-05-31 13:41:53 +01:00
Samuel Colvin 9ecae91dad allow Any, fix #21 2017-05-31 12:07:29 +01:00
Samuel Colvin 94402d0627 allow set validation, fix #17 2017-05-31 11:59:41 +01:00
Samuel Colvin 1eca45ae11 implementing allow_extra (#26)
* implementing allow_extra

* tests for allow_extra
2017-05-31 11:19:25 +01:00
Samuel Colvin 35add310cc improve error display 2017-05-10 12:43:29 +01:00
Samuel Colvin ddb8e96401 allow tuples, also infer types for falsy, fix #11 2017-05-10 11:17:07 +01:00
Samuel Colvin 24b9fdcd86 removing 'validator' from exception message 2017-05-08 17:43:39 +01:00
Samuel Colvin d6edca642a allow None as value in None fields 2017-05-08 12:34:20 +01:00
Samuel Colvin 017d3f03be BaseModel equality 2017-05-08 11:59:49 +01:00
Samuel Colvin 3673c11d53 improving coverage 2017-05-08 11:54:43 +01:00
Samuel Colvin 63197fc34b cleaning up error display, enabling list parsing 2017-05-06 14:10:40 +01:00
Samuel Colvin 0214be13a5 proper support for unions 2017-05-06 00:10:48 +01:00
Samuel Colvin 7950e7f909 enum support and better type check 2017-05-05 21:10:49 +01:00
Samuel Colvin e2d4460429 add 'allow_extra' checks 2017-05-05 20:26:14 +01:00
Samuel Colvin 7254ddc5e6 improve test coverage 2017-05-05 18:05:42 +01:00
Samuel Colvin c333ba755c best support resolution of 2017-05-05 15:13:15 +01:00