Skip to content

Commit 23506c0

Browse files
committed
Fix py2
1 parent 5d8a178 commit 23506c0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

coconut/compiler/header.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,12 @@ def base_async_def(
238238
return prepare(out, **kwargs)
239239

240240

241-
def make_py_str(str_contents, target, after_py_str_defined=False):
242-
"""Get code that effectively wraps the given code in py_str."""
241+
def make_py_str(str_contents, target, after_py_str_defined):
242+
"""Get code that effectively wraps the given str in py_str."""
243243
return (
244244
repr(str_contents) if target.startswith("3")
245245
else "b" + repr(str_contents) if target.startswith("2")
246-
else "py_str(" + repr(str_contents) + ")" if after_py_str_defined
246+
else "_coconut_py_str(" + repr(str_contents) + ")" if after_py_str_defined
247247
else "str(" + repr(str_contents) + ")"
248248
)
249249

@@ -285,9 +285,12 @@ def process_header_args(which, use_hash, target, no_tco, strict, no_wrap):
285285
_coconut_="_coconut_" if which != "__coconut__" else "", # only for aliases defined at the end of the header
286286
VERSION_STR=VERSION_STR,
287287
module_docstring='"""Built-in Coconut utilities."""\n\n' if which == "__coconut__" else "",
288-
__coconut__=make_py_str("__coconut__", target),
289-
_coconut_cached__coconut__=make_py_str("_coconut_cached__coconut__", target),
290-
coconut_cache_dir=make_py_str(coconut_cache_dir, target),
288+
__coconut__=make_py_str("__coconut__", target, after_py_str_defined=False),
289+
_coconut_cached__coconut__=make_py_str("_coconut_cached__coconut__", target, after_py_str_defined=False),
290+
coconut_cache_dir=make_py_str(coconut_cache_dir, target, after_py_str_defined=False),
291+
py_str_module=make_py_str("module", target, after_py_str_defined=True),
292+
py_str_typing=make_py_str("typing", target, after_py_str_defined=True),
293+
py_str_MatchError=make_py_str("MatchError", target, after_py_str_defined=True),
291294
object="" if target.startswith("3") else "(object)",
292295
comma_object="" if target.startswith("3") else ", object",
293296
comma_slash=", /" if target_info >= (3, 8) else "",

coconut/compiler/templates/header.py_template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def _coconut_lazy_module(name, on_import=None, attr=None):
2525
return _coconut.dir(load())
2626
except _coconut.ImportError:
2727
return []
28-
return meta("_coconut_lazy_module", (), {{}})
28+
return meta({py_str_module}, (), {{}})
2929
@_coconut_wraps(_coconut_py_super)
3030
def _coconut_super(type=None, object_or_type=None):
3131
if type is None:
@@ -50,7 +50,7 @@ class _coconut{object}:{COMMENT.EVERYTHING_HERE_MUST_BE_COPIED_TO_STUB_FILE}
5050
{import_pickle}
5151
{import_OrderedDict}
5252
{import_collections_abc}
53-
typing = types.ModuleType(_coconut_py_str("typing"))
53+
typing = types.ModuleType({py_str_typing})
5454
try:
5555
import typing_extensions
5656
except ImportError:
@@ -1399,7 +1399,7 @@ def _coconut_get_function_match_error():
13991399
class _coconut_base_pattern_func(_coconut_base_callable):{COMMENT.no_slots_to_allow_func_attrs}
14001400
_coconut_is_match = True
14011401
def __init__(self, *funcs):
1402-
self.FunctionMatchError = _coconut.type(_coconut_py_str("MatchError"), ({_coconut_}MatchError,), {empty_py_dict})
1402+
self.FunctionMatchError = _coconut.type({py_str_MatchError}, ({_coconut_}MatchError,), {empty_py_dict})
14031403
self.patterns = []
14041404
self.__doc__ = None
14051405
self.__name__ = None

0 commit comments

Comments
 (0)