Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MyPy workaround for TypedDicts #16408

Open
julienp opened this issue Jun 17, 2024 · 0 comments
Open

Remove MyPy workaround for TypedDicts #16408

julienp opened this issue Jun 17, 2024 · 0 comments
Labels
area/codegen SDK-gen, program-gen, convert awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). blocked The issue cannot be resolved without 3rd party action. kind/enhancement Improvements or new features language/python

Comments

@julienp
Copy link
Contributor

julienp commented Jun 17, 2024

Running mypy gets very slow when there are a lot of TypedDicts. To work around this, the types generated by #15957 are conditional on the used type checker to work around perf issues in MyPy and PyCharm, see #12689 (comment)

if not MYPY:
    class DeploymentArgsDict(TypedDict):
        api_version: NotRequired[Input[str]]
        kind: NotRequired[Input[str]]
        metadata: NotRequired[Input['ObjectMetaArgsDict']]
        ...
elif False:
    DeploymentArgsDict: TypeAlias = Mapping[str, Any]

Once this is fixed in MyPY https://github.com/python/mypy/issues/ and PyCharm https://youtrack.jetbrains.com/issue/PY-72690/Slow-code-analysis-for-Python-code-using-many-TypedDict we can get rid of the workaround.

@julienp julienp added kind/enhancement Improvements or new features language/python labels Jun 17, 2024
github-merge-queue bot pushed a commit that referenced this issue Jun 18, 2024
Epic: Improved Typing #12689

This PR adds the flag `Languages.Python.InputTypes` to the schema, which
can take the values `classes` or `classes-and-dicts`. In the first
iteration of the feature, this defaults to `classes`, which leaves code
generation as is and does not change input types.. If the flag is set to
`classes-and-dicts`, `TypedDict` based types are generated next to the
current `<Type>Args` classes. In the future this could be extended to
support `dicts` to generate only `TypedDict` types.

The generated types are conditional on the used type checker to work
around perf issues in MyPy and PyCharm, see
#12689 (comment)

```python
if not MYPY:
    class DeploymentArgsDict(TypedDict):
        api_version: NotRequired[Input[str]]
        kind: NotRequired[Input[str]]
        metadata: NotRequired[Input['ObjectMetaArgsDict']]
        ...
elif False:
    DeploymentArgsDict: TypeAlias = Mapping[str, Any]
```

Removing the workaround is tracked in
#16408

---------

Co-authored-by: Anthony King <anthony@datapane.com>
Co-authored-by: Justin Van Patten <jvp@justinvp.com>
@justinvp justinvp added awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). blocked The issue cannot be resolved without 3rd party action. area/codegen SDK-gen, program-gen, convert labels Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/codegen SDK-gen, program-gen, convert awaiting-upstream The issue cannot be resolved without action in another repository (may be owned by Pulumi). blocked The issue cannot be resolved without 3rd party action. kind/enhancement Improvements or new features language/python
Projects
None yet
Development

No branches or pull requests

2 participants