From 48b6d770ca5c2c752e69fb637ac2456ea42361cf Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Mon, 19 Feb 2024 15:17:42 -0600 Subject: [PATCH 1/7] DictOfNamedArrays: better repr, keys --- pytato/array.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pytato/array.py b/pytato/array.py index c08209290..0455b4498 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -173,7 +173,7 @@ import operator import attrs from typing import ( - Optional, Callable, ClassVar, Dict, Any, Mapping, Tuple, Union, + KeysView, Optional, Callable, ClassVar, Dict, Any, Mapping, Tuple, Union, Protocol, Sequence, cast, TYPE_CHECKING, List, Iterator, TypeVar, FrozenSet, Collection) @@ -845,7 +845,12 @@ def __iter__(self) -> Iterator[str]: return iter(self._data) def __repr__(self) -> str: - return "DictOfNamedArrays(" + str(self._data) + ")" + return "DictOfNamedArrays(" + repr(self._data) + ")" + + # Note: items() and values() are not implemented here, they go through + # __iter__()/__getitem__() above. + def keys(self) -> KeysView[str]: + return self._data.keys() # }}} From b411c395bb8798636e4efe4d1410fb4340120973 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Mon, 19 Feb 2024 16:12:45 -0600 Subject: [PATCH 2/7] add tags to repr --- pytato/array.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytato/array.py b/pytato/array.py index 0455b4498..fa7d7b406 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -845,7 +845,7 @@ def __iter__(self) -> Iterator[str]: return iter(self._data) def __repr__(self) -> str: - return "DictOfNamedArrays(" + repr(self._data) + ")" + return f"DictOfNamedArrays(tags={self.tags!r}, data={self._data!r})" # Note: items() and values() are not implemented here, they go through # __iter__()/__getitem__() above. From 9aa7b8225bf860444c5ab5f20db3e3ec5d6b29ee Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Fri, 23 Feb 2024 14:36:21 -0600 Subject: [PATCH 3/7] make keys() abstract --- pytato/array.py | 4 ++++ pytato/function.py | 6 +++++- pytato/loopy.py | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pytato/array.py b/pytato/array.py index fa7d7b406..aab6529b9 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -797,6 +797,10 @@ def __eq__(self, other: Any) -> bool: from pytato.equality import EqualityComparer return EqualityComparer()(self, other) + @abstractmethod + def keys(self) -> KeysView[str]: + pass + @attrs.frozen(eq=False, init=False) class DictOfNamedArrays(AbstractResultWithNamedArrays): diff --git a/pytato/function.py b/pytato/function.py index 5c4d40d46..6fd6b0c55 100644 --- a/pytato/function.py +++ b/pytato/function.py @@ -48,7 +48,8 @@ import enum from typing import (Callable, Dict, FrozenSet, Tuple, Union, TypeVar, Optional, - Hashable, Sequence, ClassVar, Iterator, Iterable, Mapping) + Hashable, Sequence, ClassVar, Iterator, Iterable, Mapping, + KeysView) from immutabledict import immutabledict from functools import cached_property from pytato.array import (Array, AbstractResultWithNamedArrays, @@ -306,6 +307,9 @@ def __len__(self) -> int: def _with_new_tags(self: Call, tags: FrozenSet[Tag]) -> Call: return attrs.evolve(self, tags=tags) + def keys(self) -> KeysView[str]: + return self.function.returns.keys() + # }}} diff --git a/pytato/loopy.py b/pytato/loopy.py index fea9274bd..aa14f5b54 100644 --- a/pytato/loopy.py +++ b/pytato/loopy.py @@ -130,6 +130,10 @@ def __len__(self) -> int: def __iter__(self) -> Iterator[str]: return iter(self._result_names) + # type-ignore-reason: AbstractResultWithNamedArrays returns a KeysView here + def keys(self) -> FrozenSet[str]: # type: ignore[override] + return self._result_names + @attrs.frozen(eq=False, hash=True, cache_hash=True) class LoopyCallResult(NamedArray): From b5ab8d55a5b7fa01958a19630e250faefe114a2b Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Fri, 23 Feb 2024 16:24:44 -0600 Subject: [PATCH 4/7] add to doc --- pytato/array.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pytato/array.py b/pytato/array.py index aab6529b9..9290dab31 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -761,6 +761,7 @@ class AbstractResultWithNamedArrays(Mapping[str, NamedArray], Taggable, ABC): .. automethod:: __contains__ .. automethod:: __getitem__ .. automethod:: __len__ + .. automethod:: keys .. note:: @@ -799,6 +800,7 @@ def __eq__(self, other: Any) -> bool: @abstractmethod def keys(self) -> KeysView[str]: + """Return a :class:`KeysView` of the names of the named arrays.""" pass From 34fd56b8d392b13c853a911d134349ff5ddef666 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Tue, 19 Nov 2024 15:39:37 -0600 Subject: [PATCH 5/7] fix lint --- pytato/array.py | 10 +++++++++- pytato/function.py | 12 ++++++++---- pytato/loopy.py | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/pytato/array.py b/pytato/array.py index 090f2ce40..4e241883d 100644 --- a/pytato/array.py +++ b/pytato/array.py @@ -176,7 +176,15 @@ import operator import re from abc import ABC, abstractmethod -from collections.abc import Callable, Collection, Iterable, Iterator, KeysView, Mapping, Sequence +from collections.abc import ( + Callable, + Collection, + Iterable, + Iterator, + KeysView, + Mapping, + Sequence, +) from functools import cached_property, partialmethod from typing import ( TYPE_CHECKING, diff --git a/pytato/function.py b/pytato/function.py index 4b590c668..6ebcd4a12 100644 --- a/pytato/function.py +++ b/pytato/function.py @@ -57,7 +57,14 @@ import enum import re -from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping +from collections.abc import ( + Callable, + Hashable, + Iterable, + Iterator, + KeysView, + Mapping, +) from functools import cached_property from typing import ( Any, @@ -65,9 +72,6 @@ TypeVar, ) -from typing import (Callable, Dict, FrozenSet, Tuple, Union, TypeVar, Optional, - Hashable, Sequence, ClassVar, Iterator, Iterable, Mapping, - KeysView) import attrs from immutabledict import immutabledict diff --git a/pytato/loopy.py b/pytato/loopy.py index 6ad3c0218..21e642327 100644 --- a/pytato/loopy.py +++ b/pytato/loopy.py @@ -151,7 +151,7 @@ def __iter__(self) -> Iterator[str]: return iter(self._result_names) # type-ignore-reason: AbstractResultWithNamedArrays returns a KeysView here - def keys(self) -> FrozenSet[str]: # type: ignore[override] + def keys(self) -> frozenset[str]: # type: ignore[override] return self._result_names From e7cdb1fb546d52fc701e24512967469498892b7a Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Tue, 19 Nov 2024 15:53:17 -0600 Subject: [PATCH 6/7] remove invalid requirements.txt pytools version specification --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 043cbf347..b1f1df20a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -git+https://github.com/inducer/pytools.git#egg=pytools >= 2024.1.14 +git+https://github.com/inducer/pytools.git#egg=pytools git+https://github.com/inducer/pymbolic.git#egg=pymbolic git+https://github.com/inducer/genpy.git#egg=genpy git+https://github.com/inducer/loopy.git#egg=loopy From 8836d412c626311dd0843ef1601f6ce0cab72ac6 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Mon, 25 Nov 2024 00:25:43 -0600 Subject: [PATCH 7/7] Fix sphinx doc build fail --- pytato/scalar_expr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytato/scalar_expr.py b/pytato/scalar_expr.py index 079430867..2e66828cd 100644 --- a/pytato/scalar_expr.py +++ b/pytato/scalar_expr.py @@ -10,7 +10,7 @@ .. class:: Expression - See :attr:`pymbolic.typing.Expression`. + See :data:`pymbolic.typing.Expression`. """ # FIXME: Unclear why the direct links to pymbolic don't work