Skip to content

Commit 6689aa3

Browse files
feat: fully support Python 3.14 (#3913)
Co-authored-by: Roger Zhang <[email protected]>
1 parent ea9b220 commit 6689aa3

5 files changed

Lines changed: 9 additions & 29 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
- "3.11"
2525
- "3.12"
2626
- "3.13"
27+
- "3.14"
2728
steps:
2829
- uses: actions/checkout@v6
2930
- uses: actions/setup-python@v6

DEVELOPMENT_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Environment setup
2626
-----------------
2727
### 1. Install Python versions
2828

29-
Our officially supported Python versions are 3.10, 3.11, 3.12, 3.13
29+
Our officially supported Python versions are 3.10, 3.11, 3.12, 3.13, 3.14
3030
Our CI/CD pipeline is setup to run unit tests against Python 3 versions. Make sure you test it before sending a Pull Request.
3131
See [Unit testing with multiple Python versions](#unit-testing-with-multiple-python-versions).
3232

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.black]
22
line-length = 120
3-
target_version = ['py310', 'py311', 'py312', 'py313']
3+
target_version = ['py310', 'py311', 'py312', 'py313', 'py314']
44
exclude = '''
55
66
(

requirements/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ jsonschema<5,>=4.23
33
typing_extensions>=4.4
44

55
# resource validation & schema generation
6-
pydantic~=2.12.5
6+
pydantic~=2.13.3

samtranslator/model/sam_resources.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import copy
44
import re
5-
import sys
65
from collections.abc import Callable
76
from contextlib import suppress
8-
from types import ModuleType
97
from typing import Any, Literal, Union, cast
108

119
import samtranslator.model.eventsources
@@ -37,19 +35,11 @@
3735
SyncConfigType,
3836
UserPoolConfigType,
3937
)
40-
41-
# Pydantic 1 doesn't support Python 3.14 so these imports will fail until we migrate to v2
42-
try:
43-
from samtranslator.internal.schema_source import (
44-
aws_serverless_capacity_provider,
45-
aws_serverless_function,
46-
aws_serverless_graphqlapi,
47-
)
48-
except RuntimeError: # Pydantic fails when initializing the model classes with a RuntimeError in 3.14
49-
aws_serverless_capacity_provider = cast(ModuleType, None)
50-
aws_serverless_function = cast(ModuleType, None)
51-
aws_serverless_graphqlapi = cast(ModuleType, None)
52-
38+
from samtranslator.internal.schema_source import (
39+
aws_serverless_capacity_provider,
40+
aws_serverless_function,
41+
aws_serverless_graphqlapi,
42+
)
5343
from samtranslator.internal.schema_source.common import PermissionsType, SamIntrinsicable
5444
from samtranslator.internal.types import GetManagedPolicyMap
5545
from samtranslator.internal.utils.utils import passthrough_value, remove_none_values
@@ -158,14 +148,6 @@
158148
_CONDITION_CHAR_LIMIT = 255
159149

160150

161-
# Utility function to throw an error when using functionality that doesn't work in Python 3.14 (need migration to Pydantic v2)
162-
def check_python_314_compatibility(module: ModuleType | None, functionality: str) -> None:
163-
if sys.version_info >= (3, 14) and module is None:
164-
raise RuntimeError(
165-
f"{functionality} functionalities are temporarily not supported when running SAM in Python 3.14"
166-
)
167-
168-
169151
class SamFunction(SamResourceMacro):
170152
"""SAM function macro."""
171153

@@ -811,7 +793,6 @@ def _transform_capacity_provider_config(self) -> dict[str, Any]:
811793

812794
# Validate CapacityProviderConfig using Pydantic model directly for comprehensive error collection
813795
try:
814-
check_python_314_compatibility(aws_serverless_function, "Capacity Provider")
815796
validated_model = aws_serverless_function.CapacityProviderConfig.parse_obj(self.CapacityProviderConfig)
816797
except Exception as e:
817798
raise InvalidResourceException(self.logical_id, f"Invalid CapacityProviderConfig: {e!s}") from e
@@ -1574,7 +1555,6 @@ def to_cloudformation(self, **kwargs: Any) -> list[Resource]:
15741555
"""
15751556
Transform the SAM CapacityProvider resource to CloudFormation
15761557
"""
1577-
check_python_314_compatibility(aws_serverless_capacity_provider, "Capacity Provider")
15781558
self.validate_before_transform(
15791559
schema_class=aws_serverless_capacity_provider.Properties,
15801560
collect_all_errors=True,
@@ -2792,7 +2772,6 @@ def __init__(
27922772

27932773
@cw_timer
27942774
def to_cloudformation(self, **kwargs: Any) -> list[Resource]:
2795-
check_python_314_compatibility(aws_serverless_graphqlapi, "GraphQLApi")
27962775
model = self.validate_properties_and_return_model(aws_serverless_graphqlapi.Properties)
27972776

27982777
appsync_api, cloudwatch_role, auth_connectors = self._construct_appsync_api_resources(model)

0 commit comments

Comments
 (0)