Skip to content

Commit

Permalink
Fix anon namedtuples
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Aug 25, 2024
1 parent 4a37f04 commit 16f7e58
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions coconut/compiler/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ def recursive_iterator(*args, **kwargs):
''',
indent=1,
),
set_nt_match_args=pycondition(
set_NT_match_args=pycondition(
(3, 10),
if_lt=r'''
nt.__match_args__ = nt._fields
NT.__match_args__ = _coconut.property(lambda self: self._fields)
''',
indent=1,
newline=True,
Expand Down
7 changes: 3 additions & 4 deletions coconut/compiler/templates/header.py_template
Original file line number Diff line number Diff line change
Expand Up @@ -2023,11 +2023,10 @@ def _coconut_mk_anon_namedtuple(fields, types=None, of_kwargs={empty_dict}, of_a
else:
NT = _coconut.typing.NamedTuple("_namedtuple_of", [(f, t) for f, t in _coconut.zip(fields, types)])
_coconut.copyreg.pickle(NT, lambda nt: (_coconut_mk_anon_namedtuple, (nt._fields, types, nt._asdict())))
if not (of_kwargs or of_args):
{set_NT_match_args} if of_kwargs or of_args:
return NT(*of_args, **of_kwargs)
else:
return NT
nt = NT(*of_args, **of_kwargs)
{set_nt_match_args}
return nt
def _coconut_ndim(arr):
arr_mod = _coconut_get_base_module(arr)
if (arr_mod in _coconut.numpy_modules or _coconut.hasattr(arr.__class__, "__matconcat__")) and _coconut.hasattr(arr, "ndim"):
Expand Down
2 changes: 1 addition & 1 deletion coconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = "3.1.1"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 5
DEVELOP = 6
ALPHA = False # for pre releases rather than post releases

assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1"
Expand Down
1 change: 1 addition & 0 deletions coconut/tests/src/cocotest/agnostic/primary_2.coco
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ def primary_test_2() -> bool:
match (x=) in (x=13, y=13):
assert False
assert x == 12
assert (x=1).__match_args__ == ('x',) # type: ignore

with process_map.multiple_sequential_calls(): # type: ignore
assert map((+), range(3), range(4)$[:-1], strict=True) |> list == [0, 2, 4] == process_map((+), range(3), range(4)$[:-1], strict=True) |> list # type: ignore
Expand Down

0 comments on commit 16f7e58

Please sign in to comment.