mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
d8e8e6a780
* 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