MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _hash_limit_string

Class _hash_limit_string

lib/sqlalchemy/util/langhelpers.py:1765–1792  ·  view source on GitHub ↗

A string subclass that can only be hashed on a maximum amount of unique values. This is used for warnings so that we can send out parameterized warnings without the __warningregistry__ of the module, or the non-overridable "once" registry within warnings.py, overloading memory,

Source from the content-addressed store, hash-verified

1763
1764
1765class _hash_limit_string(str):
1766 """A string subclass that can only be hashed on a maximum amount
1767 of unique values.
1768
1769 This is used for warnings so that we can send out parameterized warnings
1770 without the __warningregistry__ of the module, or the non-overridable
1771 "once" registry within warnings.py, overloading memory,
1772
1773
1774 """
1775
1776 _hash: int
1777
1778 def __new__(
1779 cls, value: str, num: int, args: Sequence[Any]
1780 ) -> _hash_limit_string:
1781 interpolated = (value % args) + (
1782 " (this warning may be suppressed after %d occurrences)" % num
1783 )
1784 self = super().__new__(cls, interpolated)
1785 self._hash = hash("%s_%d" % (value, hash(interpolated) % num))
1786 return self
1787
1788 def __hash__(self) -> int:
1789 return self._hash
1790
1791 def __eq__(self, other: Any) -> bool:
1792 return hash(self) == hash(other)
1793
1794
1795def warn(msg: str, code: Optional[str] = None) -> None:

Callers 3

warn_deprecated_limitedFunction · 0.85
warn_limitedFunction · 0.85

Calls

no outgoing calls

Tested by 1