Skip to content

Commit

Permalink
Add 3.13 support
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Jul 16, 2023
1 parent 928755d commit 4b143e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ If the version of Python that the compiled code will be running on is known ahea
- `3.10`: will work on any Python `>= 3.10`
- `3.11`: will work on any Python `>= 3.11`
- `3.12`: will work on any Python `>= 3.12`
- `3.13`: will work on any Python `>= 3.12`
- `sys`: chooses the target corresponding to the current Python version
- `psf`: chooses the target corresponding to the oldest Python version not considered [end-of-life](https://devguide.python.org/versions/) by the PSF (Python Software Foundation)

Expand Down Expand Up @@ -1850,7 +1851,7 @@ Since Coconut syntax is a superset of Python 3 syntax, it supports [Python 3 fun

Since not all supported Python versions support the [`typing`](https://docs.python.org/3/library/typing.html) module, Coconut provides the [`TYPE_CHECKING`](#type_checking) built-in for hiding your `typing` imports and `TypeVar` definitions from being executed at runtime. Coconut will also automatically use [`typing_extensions`](https://pypi.org/project/typing-extensions/) over `typing` objects at runtime when importing them from `typing`, even when they aren't natively supported on the current Python version (this works even if you just do `import typing` and then `typing.<Object>`).

Furthermore, when compiling type annotations to Python 3 versions without [PEP 563](https://www.python.org/dev/peps/pep-0563/) support, Coconut wraps annotation in strings to prevent them from being evaluated at runtime (note that `--no-wrap-types` disables all wrapping, including via PEP 563 support).
Furthermore, when compiling type annotations to Python 3 versions without [PEP 563](https://www.python.org/dev/peps/pep-0563/) support, Coconut wraps annotation in strings to prevent them from being evaluated at runtime (to avoid this, e.g. if you want to use annotations at runtime, `--no-wrap-types` will disable all wrapping, including via PEP 563 support). Only on Python 3.13+ does `--no-wrap-types` do nothing, since there [PEP 649](https://peps.python.org/pep-0649/) support is used instead.

Additionally, Coconut adds special syntax for making type annotations easier and simpler to write. When inside of a type annotation, Coconut treats certain syntax constructs differently, compiling them to type annotations instead of what they would normally represent. Specifically, Coconut applies the following transformations:
```coconut
Expand Down
8 changes: 5 additions & 3 deletions coconut/compiler/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,11 @@ def getheader(which, use_hash, target, no_tco, strict, no_wrap):

if not target.startswith("3"):
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)
# 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
header += "from __future__ import generator_stop\n"
elif target_info >= (3, 7):
if no_wrap:
header += "from __future__ import generator_stop\n"
Expand Down
4 changes: 4 additions & 0 deletions coconut/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,18 @@ def get_bool_env_var(env_var, default=False):
(3, 10),
(3, 11),
(3, 12),
(3, 13),
)

py_vers_with_eols = (
# must be in ascending order and kept up-to-date with https://devguide.python.org/versions
# (target, eol date)
("38", dt.datetime(2024, 11, 1)),
("39", dt.datetime(2025, 11, 1)),
("310", dt.datetime(2026, 11, 1)),
("311", dt.datetime(2027, 11, 1)),
("312", dt.datetime(2028, 11, 1)),
("313", dt.datetime(2028, 11, 1)),
)

# must match supported vers above and must be replicated in DOCS
Expand All @@ -208,6 +211,7 @@ def get_bool_env_var(env_var, default=False):
"310",
"311",
"312",
"313",
)
pseudo_targets = {
"universal": "",
Expand Down

0 comments on commit 4b143e3

Please sign in to comment.