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
804 changes: 2 additions & 802 deletions .basedpyright/baseline.json

Large diffs are not rendered by default.

18 changes: 2 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ jobs:
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-pylint.sh
. ./prepare-and-run-pylint.sh "$(basename $GITHUB_REPOSITORY)"

mypy:
name: Mypy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
-
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: "Main Script"
run: |
EXTRA_INSTALL="numpy"
curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-mypy.sh
. ./prepare-and-run-mypy.sh python3 mypy

basedpyright:
runs-on: ubuntu-latest
steps:
Expand All @@ -86,7 +71,8 @@ jobs:
curl -L -O https://tiker.net/ci-support-v0
. ./ci-support-v0
build_py_project_in_venv
sudo apt install libopenmpi-dev
sudo apt update
sudo apt -y install libopenmpi-dev
pip install numpy attrs orderedsets pytest mpi4py matplotlib
pip install basedpyright
basedpyright
Expand Down
9 changes: 0 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ Ruff:
except:
- tags

Mypy:
script:
- curl -L -O https://gitlab.tiker.net/inducer/ci-support/raw/main/prepare-and-run-mypy.sh
- ". ./prepare-and-run-mypy.sh python3 mypy"
tags:
- python3
except:
- tags

Pylint:
script:
- EXTRA_INSTALL="numpy pymbolic orderedsets siphash24"
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ reportImportCycles = "none"
pythonVersion = "3.10"
pythonPlatform = "All"

[[tool.basedpyright.executionEnvironments]]
root = "pytools/test"
reportUnknownArgumentType = "hint"
reportPrivateUsage = "none"

[tool.mypy]
python_version = "3.10"
ignore_missing_imports = true
Expand Down
16 changes: 11 additions & 5 deletions pytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2226,13 +2226,15 @@ def generate_unique_names(prefix):


def generate_numbered_unique_names(
prefix: str, num: int | None = None) -> Iterable[tuple[int, str]]:
prefix: str,
num: int | None = None,
suffix: str = "") -> Iterable[tuple[int, str]]:
if num is None:
yield (0, prefix)
yield (0, prefix + suffix)
num = 0

while True:
name = f"{prefix}_{num}"
name = f"{prefix}_{num}{suffix}"
num += 1
yield (num, name)

Expand All @@ -2254,19 +2256,22 @@ class UniqueNameGenerator:
"""
def __init__(self,
existing_names: Collection[str] | None = None,
forced_prefix: str = ""):
forced_prefix: str = "",
forced_suffix: str = "") -> None:
"""
Create a new :class:`UniqueNameGenerator`.

:arg existing_names: a :class:`set` of existing names that will be
skipped when generating new names.
:arg forced_prefix: all generated :class:`str` have this prefix.
:arg forced_suffix: all generated :class:`str` have this suffix.
"""
if existing_names is None:
existing_names = set()

self.existing_names = set(existing_names)
self.forced_prefix = forced_prefix
self.forced_suffix: str = forced_suffix
self.prefix_to_counter: dict[str, int] = {}

def is_name_conflicting(self, name: str) -> bool:
Expand Down Expand Up @@ -2326,7 +2331,8 @@ def __call__(self, based_on: str = "id") -> str:

# }}}

for counter, var_name in generate_numbered_unique_names(based_on, counter): # noqa: B020,B007
for counter, var_name in generate_numbered_unique_names( # noqa: B020,B007
based_on, counter, self.forced_suffix):
if not self.is_name_conflicting(var_name):
break

Expand Down
7 changes: 7 additions & 0 deletions pytools/persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class RecommendedHashNotFoundWarning(UserWarning):
.. autoexception:: ReadOnlyEntryError

.. autoexception:: CollisionWarning
.. autoexception:: NanKeyWarning

.. autoclass:: KeyBuilder
.. autoclass:: PersistentDict
Expand All @@ -105,6 +106,11 @@ class RecommendedHashNotFoundWarning(UserWarning):

# {{{ key generation

class NanKeyWarning(UserWarning):
"""Warning raised when a NaN is encountered while hashing a key in
:class:`KeyBuilder`."""


class KeyBuilder:
"""A (stateless) object that computes persistent hashes of objects fed to it.
Subclassing this class permits customizing the computation of hash keys.
Expand Down Expand Up @@ -267,6 +273,7 @@ def update_for_float(self, key_hash: Hash, key: float) -> None:
warn("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.",
NanKeyWarning,
stacklevel=1)

key_hash.update(key.hex().encode("utf8"))
Expand Down
Loading
Loading