diff --git a/DOCS.md b/DOCS.md index bbc4c5108..e0d4ea342 100644 --- a/DOCS.md +++ b/DOCS.md @@ -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) @@ -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.`). -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 diff --git a/coconut/compiler/header.py b/coconut/compiler/header.py index b166ff831..a108ba5c8 100644 --- a/coconut/compiler/header.py +++ b/coconut/compiler/header.py @@ -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" diff --git a/coconut/constants.py b/coconut/constants.py index c05c3c4cc..4251f6334 100644 --- a/coconut/constants.py +++ b/coconut/constants.py @@ -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 @@ -208,6 +211,7 @@ def get_bool_env_var(env_var, default=False): "310", "311", "312", + "313", ) pseudo_targets = { "universal": "",