Commit Graph

16 Commits

Author SHA1 Message Date
Eric Jolibois 37c37fd55e fix(mypy): fix custom Path and UUID related types (#2420)
* add tests that should pass

But we have those errors

226: error: Item "str" of "Union[UUID, str]" has no attribute "hex"  [union-attr]
227: error: Item "str" of "Union[UUID, str]" has no attribute "hex"  [union-attr]
228: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]
229: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]
230: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]
231: error: Item "str" of "Union[Path, str]" has no attribute "absolute"  [union-attr]

* fix: right types should be valid

* remove new useless `type: ignore`

* docs: add change file
2021-03-02 12:07:07 +00:00
Eric Jolibois 7da04d95fa fix(mypy): remove complaints about most custom _pydantic_ types (#2099)
* fix(mypy): handle FilePath and DirectoryPath custom types

closes #2098

* fix(mypy): handle almost all other custom types

* remove mypy overwrite when extra logic is set

* fix unused mypy ignore
2021-02-23 12:05:42 +00:00
Raphael Huille d8e8e6a780 Generate a hash function when frozen is True (#1881)
* feature: add a `frozen` parameter to config

For now, `frozen` is a strict duplication of `allow_mutation` parameter
i.e. setting `frozen=True` does everything that `allow_mutation=False` does.

NB: this does not change the behavior of `allow_mutation`.

In next commit, setting `frozen=True` will also make the BaseModel hashable
while the existing behavior of `allow_mutation` will not be updated.

* refactor: factorise immutability tests

* feature: generate a hash function when frozen is True

Now, setting `frozen=True` also generate a hash function for the model
i.e. `__hash__` is not `None`. This makes instances of the model potentially
hashable if all the attributes are hashable. (default: `False`)

* reviewer feedback: use hash of the class instead of the super

* reviewer feedback: fix spelling checks

* reviewer feedback: update changes description

* test: remwork mypy tests in order to catch only frozen related errors

Before: there were errors about other stuff than frozen behavior
After: The modification catch only errot related to the frozen behavior

* test: split test_immutablity in 2 functions

One function tests the behavior: 'the model is mutable'
The other tests the behavior:OC 'the model is immutable'

* test mutability: remove the unnecessary parametrization

* test immutability: remove assertion that do not test frozen behavior
2021-02-23 11:45:40 +00:00
Yurii Karabas 5506d8ec19 Update type annotation for create_model function (#2071)
* Update type annotation for create_model function

* Remove redundant __base__ cast
2020-11-29 17:34:12 +00:00
layday e899692654 Add two overload variants to validate_arguments (#2055)
* Add two overload variants to `validate_arguments`

Fixes #2052.

* Add change file

* Move decorator tests to success.py

* Reword changelog entry
2020-10-28 19:09:24 +00:00
Alex Hedges 8aad3a2f58 Refactor PrivateAttr to type-check like Field (#2057)
* Refactor PrivateAttr to type-check like Field

* Change TypeError to ValueError for consistency

* Add PrivateAttr example to mypy tests
2020-10-28 10:17:45 +00:00
Sergey Teplyakov 52aa5c456f Add init for forward ref stub (#1739)
* Add __init__ for ForwardRef stub

* Add changes file

* Update changes/1738-sirtelemak.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>

* Add mypy check for ForwardRef

* Add Black line after if statement

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Sergey Teplyakov <s.teplyakov@fitingo.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-25 15:36:38 +00:00
Brian Maissy a89c97a3e3 add a __call__ stub to PyObject for mypy (#1849)
Co-authored-by: Brian Maissy <brian@medigate.io>
2020-10-09 12:11:23 +01:00
Selim Belhaouane b99c37e3d0 Fix #1770 (#1771) 2020-10-08 21:07:22 +01:00
Dima Boger ccd5f7b8f3 Replace exception to silent passing in mypy plugin for non-Var attributes (#1348)
* Replace exception to silent passing in mypy plugin for non-Var attributes

* Add a history file
2020-04-15 22:46:22 +01:00
Danny Weinberg a015cd01ba Have BaseModel inherit from Representation (#1319)
* Have BaseModel inherit from Representation

This changes the inheritance so that `BaseModel` *actually* inherits from `Representation`, rather than just having the same methods as it. While this doesn't actually affect the runtime, it does make mypy happier.

Fixes https://github.com/samuelcolvin/pydantic/issues/1310

* Add '__dict__' back into slots
2020-04-15 22:07:16 +01:00
Samuel Colvin 6914410f38 Validation Decorator (#1179)
* starting validation_decorator

* correct skip_pre_38

* fix coverage and type hints

* mypy tests and move to class based decorator

* 3.6 fix, prevent duplicate github actions

* correct py 3.6 check

* better errors

* cleaner field names for args and kwargs

* add change and comments

* starting docs

* back to 3.7 for docs

* docs

* bump

* add async example and fix print indents

* allow type annotations as strings

* python 3.8 in docs
2020-02-05 17:27:12 +00:00
Samuel Colvin 55f7d35727 update root_validator signature, fix #1192 (#1204) 2020-02-01 16:59:32 +00:00
Koudai Aono 33b3dc1825 mypy plugin support for dataclasses (#966)
* mypy plugin support for dataclassesv

* fix styles and types

* - change type-hint for `Config`
- change name of an expected file
- update documents

* fix broken a reference of a document.

* - update unittest
- update documents

* fix a document link

* Update docs/mypy_plugin.md

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update docs/mypy_plugin.md

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* Update docs/mypy_plugin.md

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* remove extra whitespaces on mypy test results

* fix output file name of mypy test

* Update docs/usage/dataclasses.md

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* use TypeVar for DataclassType
2019-11-14 11:26:46 +00:00
Samuel Colvin f4cc204138 fix mypy complaint on @root_validator(pre=True) (#985)
* fix mypy complaint on @root_validator(pre=True)

* fix internal mypy

* use overload on root_validator
2019-11-09 14:45:29 +00:00
dmontagu 0c18619769 Mypy plugin (#722)
* Add mypy plugin

* Make all arguments optional for BaseSettings

* Get test coverage up

* Add changes

* Add type-checking for BaseModel.construct, and checking for from_orm

* Fix formatting and linting

* Fix the build

* Heavy refactor of plugin and mypy tests

* Make linting pass

* Handle dynamic aliases

* Better organize plugin code

* Add docs

* Add support for error codes

* Fix minor docs typo

* Rename config settings, add docstrings, and incorporate other feedback

* Incorporate feedback

* Update docs, remove dataclasses for cython

* fix mypy example
2019-10-31 13:19:01 +01:00