Skip to content

fix: TYPE_CHECKING block is empty when a downstream tool strips submodule imports#5201

Open
dgandhi62 wants to merge 2 commits into
mainfrom
python-imports-12
Open

fix: TYPE_CHECKING block is empty when a downstream tool strips submodule imports#5201
dgandhi62 wants to merge 2 commits into
mainfrom
python-imports-12

Conversation

@dgandhi62

@dgandhi62 dgandhi62 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #5196

This pr emits a pass as the first statement of the generated if typing.TYPE_CHECKING: block in a module's __init__.py, so the block remains syntactically valid even if a downstream consumer removes the from . import ... lines that follow it.

if typing.TYPE_CHECKING:
    pass
    from . import submodule_a as submodule_a
    from . import submodule_b as submodule_b

We've seen this behavior in cdktf get (https://github.com/hashicorp/terraform-cdk/blob/main/packages/%40cdktf/provider-generator/lib/get/constructs-maker.ts#L713) and this workaround will unblock customers.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mergify mergify Bot added the contribution/core This is a PR that came from AWS. label Jul 13, 2026
@dgandhi62 dgandhi62 changed the title fix: keep TYPE_CHECKING block valid when a downstream tool strips submodule imports fix: TYPE_CHECKING block is empty when a downstream tool strips submodule imports Jul 13, 2026
@dgandhi62 dgandhi62 force-pushed the python-imports-12 branch from 25191f8 to 4f0c14e Compare July 14, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution/core This is a PR that came from AWS.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

python: generated __init__.py has empty 'if typing.TYPE_CHECKING:' block, causing IndentationError (regression since jsii-pacmak 1.133.0)

1 participant