Skip to content

Commit c4a239c

Browse files
author
Jerry Kindall
authored
chore(init-templates): Python app template imports 'core' as 'cdk' to align sample code across languages (#12970)
For consistency and to make it easier to translate TypeScript examples into Python, import the `aws_cdk.core` module as `cdk`. There are snippets in the CDK Developer Guide that assume the `core` module is imported as `core`. It is difficult to synchronize changes to the CDK with changes in the Guide, so this PR causes the `core` module to be imported under _both_ names. Once this change is released, the Guide snippets can be updated to use `cdk` rather than `core` to refer to the `core` module. At some point in the future, this template can be updated again to remove the now-redundant `core` import. This is to support this Guide issue: awsdocs/aws-cdk-guide#268 which intends to make all code snippets in the Guide follow the guidance in the "Working with the CDK in Python" topic. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 430c38b commit c4a239c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
from aws_cdk import core as cdk
2+
3+
# For consistency with other languages, `cdk` is the preferred import name for
4+
# the CDK's core module. The following line also imports it as `core` for use
5+
# with examples from the CDK Developer's Guide, which are in the process of
6+
# being updated to use `cdk`. You may delete this import if you don't need it.
17
from aws_cdk import core
28

39

4-
class %name.PascalCased%Stack(core.Stack):
10+
class %name.PascalCased%Stack(cdk.Stack):
511

6-
def __init__(self, scope: core.Construct, construct_id: str, **kwargs) -> None:
12+
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
713
super().__init__(scope, construct_id, **kwargs)
814

915
# The code that defines your stack goes here
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#!/usr/bin/env python3
22

3+
from aws_cdk import core as cdk
4+
5+
# For consistency with TypeScript code, `cdk` is the preferred import name for
6+
# the CDK's core module. The following line also imports it as `core` for use
7+
# with examples from the CDK Developer's Guide, which are in the process of
8+
# being updated to use `cdk`. You may delete this import if you don't need it.
39
from aws_cdk import core
410

511
from %name.PythonModule%.%name.PythonModule%_stack import %name.PascalCased%Stack
612

713

8-
app = core.App()
14+
app = cdk.App()
915
%name.PascalCased%Stack(app, "%name.StackName%")
1016

1117
app.synth()

0 commit comments

Comments
 (0)