(cls: type[BaseModel])
| 548 | |
| 549 | |
| 550 | def make_hash_func(cls: type[BaseModel]) -> Any: |
| 551 | getter = operator.itemgetter(*cls.__pydantic_fields__.keys()) if cls.__pydantic_fields__ else lambda _: 0 |
| 552 | |
| 553 | def hash_func(self: Any) -> int: |
| 554 | try: |
| 555 | return hash(getter(self.__dict__)) |
| 556 | except KeyError: |
| 557 | # In rare cases (such as when using the deprecated copy method), the __dict__ may not contain |
| 558 | # all model fields, which is how we can get here. |
| 559 | # getter(self.__dict__) is much faster than any 'safe' method that accounts for missing keys, |
| 560 | # and wrapping it in a `try` doesn't slow things down much in the common case. |
| 561 | return hash(getter(SafeGetItemProxy(self.__dict__))) |
| 562 | |
| 563 | return hash_func |
| 564 | |
| 565 | |
| 566 | def set_model_fields( |
no test coverage detected