Skip to content

Commit

Permalink
named_tuple -> SimpleNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
havogt committed Jan 31, 2024
1 parent 6711e06 commit f8814c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/gt4py/next/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,5 +1077,6 @@ def __gt_builtin_func__(cls, /, func: fbuiltins.BuiltInFunction[_R, _P]) -> Call


#: Numeric value used to represent missing values in connectivities.
#: Adopted from UGRID Conventions (http://ugrid-conventions.github.io/ugrid-conventions/)
#: Equivalent to the `_FillValue` attribute in the UGRID Conventions
#: (see: http://ugrid-conventions.github.io/ugrid-conventions/).
SKIP_VALUE: Final[int] = -1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later

import types
from collections import namedtuple
from typing import Any, Protocol, TypeVar

Expand Down Expand Up @@ -132,6 +133,9 @@ def debug_itir(tree):


class MeshDescriptor(Protocol):
@property
def name(self) -> str: ...

@property
def num_vertices(self) -> int: ...

Expand Down Expand Up @@ -204,15 +208,8 @@ def simple_mesh() -> MeshDescriptor:
assert all(len(row) == 2 for row in e2v_arr)
e2v_arr = np.asarray(e2v_arr, dtype=gtx.IndexType)

return namedtuple(
"SimpleMesh",
[
"num_vertices",
"num_edges",
"num_cells",
"offset_provider",
],
)(
return types.SimpleNamespace(
name="simple_mesh",
num_vertices=num_vertices,
num_edges=np.int32(num_edges),
num_cells=num_cells,
Expand Down Expand Up @@ -295,15 +292,8 @@ def skip_value_mesh() -> MeshDescriptor:
dtype=gtx.IndexType,
)

return namedtuple(
"SkipValueMesh",
[
"num_vertices",
"num_edges",
"num_cells",
"offset_provider",
],
)(
return types.SimpleNamespace(
name="skip_value_mesh",
num_vertices=num_vertices,
num_edges=num_edges,
num_cells=num_cells,
Expand Down Expand Up @@ -349,7 +339,7 @@ def skip_value_mesh() -> MeshDescriptor:
simple_mesh(),
pytest.param(skip_value_mesh(), marks=pytest.mark.uses_mesh_with_skip_values),
],
ids=lambda p: p.__class__.__name__,
ids=lambda p: p.name,
)
def mesh_descriptor(request) -> MeshDescriptor:
yield request.param

0 comments on commit f8814c8

Please sign in to comment.