From b7b9e5f75d09543e0e48f31bcde0ee770599fe04 Mon Sep 17 00:00:00 2001 From: Mark Nielsen Date: Wed, 26 May 2021 09:29:00 -0700 Subject: [PATCH] fix(python): module import fails: NameError: name 'List' is not defined (#2851) When importing a module in Python, you can get this error: ``` NameError: name 'List' is not defined ``` JSII generated code: ```python import abc import builtins import datetime import enum import typing import jsii import publication import typing_extensions from ._jsii import * __all__: List[typing.Any] = [] # <--- HERE IS THE BUG publication.publish() ``` Just need to prefix `List` with `typing.` Related issue/pr: - https://github.com/aws/jsii/issues/2750 - https://github.com/aws/jsii/pull/2757 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0 --- packages/jsii-pacmak/lib/targets/python.ts | 2 +- .../generated-code/__snapshots__/target-python.test.ts.snap | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/jsii-pacmak/lib/targets/python.ts b/packages/jsii-pacmak/lib/targets/python.ts index 868d3c0840..f68ae2264b 100644 --- a/packages/jsii-pacmak/lib/targets/python.ts +++ b/packages/jsii-pacmak/lib/targets/python.ts @@ -1607,7 +1607,7 @@ class PythonModule implements PythonType { } code.unindent(']'); } else { - code.line('__all__: List[typing.Any] = []'); + code.line('__all__: typing.List[typing.Any] = []'); } // Finally, we'll use publication to ensure that all of the non-public names diff --git a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap index 0612a6732c..e58b7a6db6 100644 --- a/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap +++ b/packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.ts.snap @@ -10589,7 +10589,7 @@ import typing_extensions from .._jsii import * -__all__: List[typing.Any] = [] +__all__: typing.List[typing.Any] = [] publication.publish() @@ -10806,7 +10806,7 @@ import typing_extensions from .._jsii import * -__all__: List[typing.Any] = [] +__all__: typing.List[typing.Any] = [] publication.publish() @@ -11163,7 +11163,7 @@ import typing_extensions from .._jsii import * -__all__: List[typing.Any] = [] +__all__: typing.List[typing.Any] = [] publication.publish()