Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
- Loading branch information
Showing
10 changed files
with
158 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add a new `frozen` boolean parameter to `Config` (default: `False`). | ||
Setting `frozen=True` does everything that `allow_mutation=False` does, and also generates a `__hash__()` method for the model. This makes instances of the model potentially hashable if all the attributes are hashable. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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