(cls: type[BaseModel], bases: tuple[type[Any], ...])
| 535 | |
| 536 | |
| 537 | def set_default_hash_func(cls: type[BaseModel], bases: tuple[type[Any], ...]) -> None: |
| 538 | base_hash_func = get_attribute_from_bases(bases, '__hash__') |
| 539 | new_hash_func = make_hash_func(cls) |
| 540 | if base_hash_func in {None, object.__hash__} or getattr(base_hash_func, '__code__', None) == new_hash_func.__code__: |
| 541 | # If `__hash__` is some default, we generate a hash function. |
| 542 | # It will be `None` if not overridden from BaseModel. |
| 543 | # It may be `object.__hash__` if there is another |
| 544 | # parent class earlier in the bases which doesn't override `__hash__` (e.g. `typing.Generic`). |
| 545 | # It may be a value set by `set_default_hash_func` if `cls` is a subclass of another frozen model. |
| 546 | # In the last case we still need a new hash function to account for new `model_fields`. |
| 547 | cls.__hash__ = new_hash_func |
| 548 | |
| 549 | |
| 550 | def make_hash_func(cls: type[BaseModel]) -> Any: |
no test coverage detected