Skip to content

Commit

Permalink
fix(python): module import fails: NameError: name 'List' is not defin…
Browse files Browse the repository at this point in the history
…ed (#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:

- #2750
- #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
  • Loading branch information
polothy authored May 26, 2021
1 parent 69c6e94 commit b7b9e5f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b7b9e5f

Please sign in to comment.