Skip to content

Commit

Permalink
Fix pyright support
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Jun 8, 2024
1 parent f8641c4 commit 7734cf8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions coconut/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
coconut_cache_dir,
coconut_sys_kwargs,
interpreter_uses_incremental,
pyright_config_file,
)
from coconut.util import (
univ_open,
Expand Down
6 changes: 5 additions & 1 deletion coconut/command/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def set_mypy_path(ensure_stubs=True):

def update_pyright_config(python_version=None):
"""Save an updated pyrightconfig.json."""
stubs_dir = install_stubs()
update_existing = os.path.exists(pyright_config_file)
with univ_open(pyright_config_file, "r+" if update_existing else "w") as config_file:
if update_existing:
Expand All @@ -518,7 +519,10 @@ def update_pyright_config(python_version=None):
raise CoconutException("invalid JSON syntax in " + repr(pyright_config_file))
else:
config = extra_pyright_args.copy()
config["extraPaths"] = [install_stubs()]
if "extraPaths" not in config:
config["extraPaths"] = []
if stubs_dir not in config["extraPaths"]:
config["extraPaths"].append(stubs_dir)
if python_version is not None:
config["pythonVersion"] = python_version
writefile(config_file, config, in_json=True, indent=tabideal)
Expand Down
4 changes: 2 additions & 2 deletions coconut/compiler/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,8 @@ def getheader(which, use_hash, target, no_tco, strict, no_wrap):
header += "from __future__ import print_function, absolute_import, unicode_literals, division\n"
# including generator_stop here is fine, even though to universalize generator returns
# we raise StopIteration errors, since we only do so when target_info < (3, 3)
elif target_info >= (3, 13):
# 3.13 supports lazy annotations, so we should just use that instead of from __future__ import annotations
elif target_info >= (3, 14):
# 3.14 supports lazy annotations, so we should just use that instead of from __future__ import annotations
header += "from __future__ import generator_stop\n"
elif target_info >= (3, 7):
if no_wrap:
Expand Down
3 changes: 3 additions & 0 deletions coconut/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def get_path_env_var(env_var, default):
(3, 11),
(3, 12),
(3, 13),
(3, 14),
)

# must be in ascending order and kept up-to-date with https://devguide.python.org/versions
Expand All @@ -233,6 +234,7 @@ def get_path_env_var(env_var, default):
("311", dt.datetime(2027, 11, 1)),
("312", dt.datetime(2028, 11, 1)),
("313", dt.datetime(2029, 11, 1)),
("314", dt.datetime(2030, 11, 1)),
)

# must match supported vers above and must be replicated in DOCS
Expand All @@ -251,6 +253,7 @@ def get_path_env_var(env_var, default):
"311",
"312",
"313",
"314",
)
pseudo_targets = {
"universal": "",
Expand Down

0 comments on commit 7734cf8

Please sign in to comment.