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,
| 1853 | |
| 1854 | |
| 1855 | class _hash_limit_string(str): |
| 1856 | """A string subclass that can only be hashed on a maximum amount |
| 1857 | of unique values. |
| 1858 | |
| 1859 | This is used for warnings so that we can send out parameterized warnings |
| 1860 | without the __warningregistry__ of the module, or the non-overridable |
| 1861 | "once" registry within warnings.py, overloading memory, |
| 1862 | |
| 1863 | |
| 1864 | """ |
| 1865 | |
| 1866 | _hash: int |
| 1867 | |
| 1868 | def __new__( |
| 1869 | cls, value: str, num: int, args: Sequence[Any] |
| 1870 | ) -> _hash_limit_string: |
| 1871 | interpolated = (value % args) + ( |
| 1872 | " (this warning may be suppressed after %d occurrences)" % num |
| 1873 | ) |
| 1874 | self = super().__new__(cls, interpolated) |
| 1875 | self._hash = hash("%s_%d" % (value, hash(interpolated) % num)) |
| 1876 | return self |
| 1877 | |
| 1878 | def __hash__(self) -> int: |
| 1879 | return self._hash |
| 1880 | |
| 1881 | def __eq__(self, other: Any) -> bool: |
| 1882 | return hash(self) == hash(other) |
| 1883 | |
| 1884 | |
| 1885 | def warn(msg: str, code: Optional[str] = None) -> None: |
no outgoing calls