From b17742daa5eb755d59063e530d8e3dcd3f5d865c Mon Sep 17 00:00:00 2001 From: Evan Hubinger Date: Tue, 20 Aug 2024 21:55:17 -0700 Subject: [PATCH] Fix py2 errors --- coconut/command/util.py | 2 +- coconut/compiler/header.py | 8 ++++++++ coconut/compiler/templates/header.py_template | 6 ++++-- coconut/constants.py | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/coconut/command/util.py b/coconut/command/util.py index fe26947d..0475616e 100644 --- a/coconut/command/util.py +++ b/coconut/command/util.py @@ -760,7 +760,7 @@ def prompt(self, msg): pygments.styles.get_style_by_name(self.style), ), completer=self.get_completer(), - auto_suggest=self.suggester, + auto_suggest=self.suggester or None, ) diff --git a/coconut/compiler/header.py b/coconut/compiler/header.py index 989e0c6a..4c93eab2 100644 --- a/coconut/compiler/header.py +++ b/coconut/compiler/header.py @@ -458,6 +458,14 @@ def recursive_iterator(*args, **kwargs): ''', indent=1, ), + set_nt_match_args=pycondition( + (3, 10), + if_lt=r''' +nt.__match_args__ = nt._fields + ''', + indent=1, + newline=True, + ), import_copyreg=pycondition( (3,), if_lt="import copy_reg as copyreg", diff --git a/coconut/compiler/templates/header.py_template b/coconut/compiler/templates/header.py_template index c5cfb8f2..7aa6a0a9 100644 --- a/coconut/compiler/templates/header.py_template +++ b/coconut/compiler/templates/header.py_template @@ -2024,8 +2024,10 @@ def _coconut_mk_anon_namedtuple(fields, types=None, of_kwargs=None): 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 of_kwargs is None: - return NT - return NT(**of_kwargs) + nt = NT + else: + nt = NT(**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"): diff --git a/coconut/constants.py b/coconut/constants.py index 14960727..995f53d6 100644 --- a/coconut/constants.py +++ b/coconut/constants.py @@ -666,7 +666,7 @@ def get_path_env_var(env_var, default): prompt_vi_mode = get_bool_env_var(vi_mode_env_var, False) prompt_wrap_lines = True prompt_history_search = True -prompt_use_suggester = False +prompt_use_suggester = not PY2 base_dir = os.path.dirname(os.path.abspath(fixpath(__file__)))