Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
466 changes: 45 additions & 421 deletions .basedpyright/baseline.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ test = [
"pytest",
"ruff",
]
siphash = [
"siphash24>=1.6",
]

[project.urls]
Documentation = "https://documen.tician.de/pytools/"
Expand Down Expand Up @@ -112,6 +109,12 @@ reportUnnecessaryIsInstance = "none"
reportUnusedCallResult = "none"
reportExplicitAny = "none"

# This reports even cycles that are qualified by 'if TYPE_CHECKING'. Not what
# we care about at this moment.
# https://github.com/microsoft/pyright/issues/746
reportImportCycles = "none"
pythonVersion = "3.10"
pythonPlatform = "All"

[tool.mypy]
python_version = "3.10"
Expand Down
15 changes: 13 additions & 2 deletions pytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
cast,
)

from typing_extensions import Self, dataclass_transform
from typing_extensions import Self, dataclass_transform, override

from pytools.version import VERSION_TEXT

Expand Down Expand Up @@ -441,6 +441,7 @@ def get_copy_kwargs(self, **kwargs):
def copy(self, **kwargs):
return self.__class__(**self.get_copy_kwargs(**kwargs))

@override
def __repr__(self):
return "{}({})".format(
self.__class__.__name__,
Expand Down Expand Up @@ -483,30 +484,36 @@ def __setstate__(self, valuedict):
fields.add(key)
setattr(self, key, value)

@override
def __eq__(self, other):
if self is other:
return True
return (self.__class__ == other.__class__
and self.__getstate__() == other.__getstate__())

@override
def __ne__(self, other):
return not self.__eq__(other)


class ImmutableRecordWithoutPickling(RecordWithoutPickling):
"""Hashable record. Does not explicitly enforce immutability."""
_cached_hash: int | None

def __init__(self, *args, **kwargs):
RecordWithoutPickling.__init__(self, *args, **kwargs)
self._cached_hash = None

def __hash__(self):
@override
def __hash__(self) -> int:
# This attribute may vanish during pickling.
if getattr(self, "_cached_hash", None) is None:
self._cached_hash = hash((
type(self),
*(getattr(self, field) for field in self.__class__.fields)
))

assert self._cached_hash is not None
return self._cached_hash


Expand Down Expand Up @@ -876,6 +883,7 @@ class keyed_memoize_method(keyed_memoize_on_first_arg): # noqa: N801
Can memoize methods on classes that do not allow setting attributes
(e.g. by overwriting ``__setattr__``), e.g. frozen :mod:`dataclasses`.
"""
@override
def _default_cache_dict_name(self, function):
return intern(f"_memoize_dic_{function.__name__}")

Expand Down Expand Up @@ -1631,6 +1639,7 @@ def _get_column_widths(self, rows) -> tuple[int, ...]:
max(len(row[i]) for row in rows) for i in range(self.ncolumns)
)

@override
def __str__(self) -> str:
"""
Returns a string representation of the table.
Expand Down Expand Up @@ -2499,10 +2508,12 @@ def done(self):
self.wall_elapsed = time.perf_counter() - self.perf_counter_start
self.process_elapsed = time.process_time() - self.process_time_start

@override
def __str__(self):
cpu = self.process_elapsed / self.wall_elapsed
return f"{self.wall_elapsed:.2f}s wall {cpu:.2f}x CPU"

@override
def __repr__(self):
wall = self.wall_elapsed
process = self.process_elapsed
Expand Down
3 changes: 3 additions & 0 deletions pytools/batchjob.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing_extensions import override


def _cp(src, dest):
from pytools import assert_not_a_file
Expand Down Expand Up @@ -134,6 +136,7 @@ def arg(self, i):
def kwarg(self, name):
return self.kwargs[name]

@override
def __str__(self):
return "{}({})".format(self.classname,
",".join(
Expand Down
3 changes: 3 additions & 0 deletions pytools/convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import numbers

import numpy as np
from typing_extensions import override


# {{{ eoc estimation --------------------------------------------------------------
Expand Down Expand Up @@ -141,6 +142,7 @@ def pretty_print(self, *,
return tbl.csv()
raise ValueError(f"unknown table type: {table_type}")

@override
def __str__(self):
return self.pretty_print()

Expand Down Expand Up @@ -211,6 +213,7 @@ def add_data_point(self, order, error):
self.orders.append(order)
self.errors.append(error)

@override
def __str__(self):
from pytools import Table
tbl = Table()
Expand Down
17 changes: 10 additions & 7 deletions pytools/datatable.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""
An in-memory relational database table
======================================

.. autoclass:: DataTable
"""

from __future__ import annotations

from typing import IO, TYPE_CHECKING, Any

from typing_extensions import override

from pytools import Record


if TYPE_CHECKING:
from collections.abc import Callable, Iterator, Sequence

__doc__ = """
An in-memory relational database table
======================================

.. autoclass:: DataTable
"""


class Row(Record):
pass
Expand Down Expand Up @@ -58,6 +60,7 @@ def __len__(self) -> int:
def __iter__(self) -> Iterator[list[Any]]:
return self.data.__iter__()

@override
def __str__(self) -> str:
"""Return a pretty-printed version of the table."""

Expand Down
4 changes: 4 additions & 0 deletions pytools/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import contextlib
import sys

from typing_extensions import override

from pytools import memoize


Expand Down Expand Up @@ -177,10 +179,12 @@ def __init__(self, source_dicts, target_dict):

self.target_dict = target_dict

@override
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
self.target_dict[key] = value

@override
def __delitem__(self, key):
dict.__delitem__(self, key)
del self.target_dict[key]
Expand Down
6 changes: 6 additions & 0 deletions pytools/lex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import re

from typing_extensions import override


class RuleError(RuntimeError):
def __init__(self, rule):
RuntimeError.__init__(self)
self.Rule = rule

@override
def __str__(self):
return repr(self.Rule)

Expand All @@ -18,6 +21,7 @@ def __init__(self, s, str_index):
self.string = s
self.index = str_index

@override
def __str__(self):
return "at index {}: ...{}...".format(
self.index, self.string[self.index:self.index+20])
Expand All @@ -30,6 +34,7 @@ def __init__(self, msg, s, token):
self.string = s
self.Token = token

@override
def __str__(self):
if self.Token is None:
return f"{self.message} at end of input"
Expand All @@ -43,6 +48,7 @@ def __init__(self, s: str, flags: int = 0) -> None:
self.Content = s
self.RE = re.compile(s, flags)

@override
def __repr__(self) -> str:
return f"RE({self.Content})"

Expand Down
14 changes: 14 additions & 0 deletions pytools/persistent_dict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing_extensions import override


"""Generic persistent, concurrent dictionary-like facility."""

Expand Down Expand Up @@ -262,7 +264,7 @@
import math
if math.isnan(key):
# Also applies to np.nan, float("nan")
warn("Encountered a NaN while hashing. Since NaNs compare unequal "

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest without Numpy

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.12 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.x ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Py3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 ubuntu-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.

Check warning on line 267 in pytools/persistent_dict.py

View workflow job for this annotation

GitHub Actions / Pytest on Pypypy3.10 macos-latest

Encountered a NaN while hashing. Since NaNs compare unequal to themselves, the resulting key can not be retrieved from a PersistentDict and will lead to a collision error on retrieval.
"to themselves, the resulting key can not be retrieved from a "
"PersistentDict and will lead to a collision error on retrieval.",
stacklevel=1)
Expand Down Expand Up @@ -573,6 +575,7 @@
"""Create the container directory to store the dictionary."""
os.makedirs(self.container_dir, exist_ok=True)

@override
def __getitem__(self, key: K) -> V:
"""Return the value associated with *key* in the dictionary."""
return self.fetch(key)
Expand All @@ -581,26 +584,31 @@
"""Store (*key*, *value*) in the dictionary."""
self.store(key, value)

@override
def __len__(self) -> int:
"""Return the number of entries in the dictionary."""
result, = next(self._exec_sql("SELECT COUNT(*) FROM dict"))
assert isinstance(result, int)
return result

@override
def __iter__(self) -> Iterator[K]:
"""Return an iterator over the keys in the dictionary."""
return self.keys()

@override
def keys(self) -> Iterator[K]: # type: ignore[override]
"""Return an iterator over the keys in the dictionary."""
for row in self._exec_sql("SELECT key_value FROM dict ORDER BY rowid"):
yield pickle.loads(row[0])[0]

@override
def values(self) -> Iterator[V]: # type: ignore[override]
"""Return an iterator over the values in the dictionary."""
for row in self._exec_sql("SELECT key_value FROM dict ORDER BY rowid"):
yield pickle.loads(row[0])[1]

@override
def items(self) -> Iterator[tuple[K, V]]: # type: ignore[override]
"""Return an iterator over the items in the dictionary."""
for row in self._exec_sql("SELECT key_value FROM dict ORDER BY rowid"):
Expand All @@ -614,6 +622,7 @@

return result

@override
def __repr__(self) -> str:
"""Return a string representation of the dictionary."""
return f"{type(self).__name__}({self.filename}, nitems={len(self)})"
Expand Down Expand Up @@ -690,6 +699,7 @@
"""
self._fetch.cache_clear()

@override
def store(self, key: K, value: V, _skip_if_present: bool = False) -> None:
keyhash = self.key_builder(key)
v = pickle.dumps((key, value))
Expand Down Expand Up @@ -730,6 +740,7 @@
key, value = pickle.loads(row[0])
return key, value

@override
def fetch(self, key: K) -> V:
keyhash = self.key_builder(key)

Expand All @@ -741,6 +752,7 @@
self._collision_check(key, stored_key)
return value

@override
def clear(self) -> None:
super().clear()
self._fetch.cache_clear()
Expand Down Expand Up @@ -796,6 +808,7 @@
enable_wal=enable_wal,
safe_sync=safe_sync)

@override
def store(self, key: K, value: V, _skip_if_present: bool = False) -> None:
keyhash = self.key_builder(key)
v = pickle.dumps((key, value))
Expand All @@ -805,6 +818,7 @@
self._exec_sql(f"INSERT OR {mode} INTO dict VALUES (?, ?)",
(keyhash, v))

@override
def fetch(self, key: K) -> V:
keyhash = self.key_builder(key)

Expand Down
Loading
Loading