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

[Python] TypedDict input types #4936

Closed
julienp opened this issue Jul 16, 2024 · 1 comment · Fixed by pulumi/pulumi#16763
Closed

[Python] TypedDict input types #4936

julienp opened this issue Jul 16, 2024 · 1 comment · Fixed by pulumi/pulumi#16763
Assignees
Labels
kind/enhancement Improvements or new features language/python resolution/fixed This issue was fixed
Milestone

Comments

@julienp
Copy link

julienp commented Jul 16, 2024

Previous discussion https://docs.google.com/document/d/1BT4ILg-q-q-XgYRuDOBOYHdNIiICWcgpewMOhMdFcjE/edit

With pulumi/pulumi#12689 we have TypedDict based types for inputs. You could previously already pass dictionaries as inputs, but these did not have type checking, and we mostly discouraged using plain dictionaries (by defaulting to Args classes in docs and examples).

Now that these are typed, we want to promote their use, and we were considering adding them to the constructor syntax in the registry docs. The option we settled on was to show the Union[${Soemthing}Args, ${Something}ArgsDict].

To accomplish this, we can pass true for acceptMapping in GetLanguageTypeString https://github.com/pulumi/pulumi/blob/ff1f7434aa8c899f94aa2b170cf225c012c8c66c/pkg/codegen/python/doc.go#L83

The result is fairly verbose:

Screenshot 2024-07-16 at 17 35 49

and also shows up in other places:

Screenshot 2024-07-16 at 17 40 41

It also does not tell the user how to use these types.

I wonder if it would be better to add a conceptual explanation to the docs in the Inputs section (for example here https://www.pulumi.com/registry/packages/kubernetes/api-docs/apps/v1/deployment/#properties), and/or on the Python SDK page, that explains that you can either use an Args class or a (typed) dictionary.

@julienp julienp self-assigned this Jul 16, 2024
@github-actions github-actions bot added the needs-triage Needs attention from the triage team label Jul 16, 2024
@github-project-automation github-project-automation bot moved this to 🤔 Triage in Docs 📚 Jul 16, 2024
@julienp julienp removed the needs-triage Needs attention from the triage team label Jul 16, 2024
@sean1588 sean1588 moved this from 🤔 Triage to 🧳 Backlog in Docs 📚 Jul 19, 2024
julienp added a commit to pulumi/docs that referenced this issue Jul 23, 2024
Document how in Python inputs can either be argument classes or
dictionary literals.

Ref pulumi/registry#4936
julienp added a commit to pulumi/docs that referenced this issue Jul 23, 2024
Document how in Python inputs can either be argument classes or
dictionary literals.

Ref pulumi/registry#4936
julienp added a commit to pulumi/pulumi that referenced this issue Jul 23, 2024
In Python object inputs can either be argument classes or dictionary
literals. Link to the Python docs in the input section of the package
docs.

Fixes pulumi/registry#4936
julienp added a commit to pulumi/pulumi that referenced this issue Jul 23, 2024
In Python object inputs can either be argument classes or dictionary
literals. Link to the Python docs in the input section of the package
docs.

Fixes pulumi/registry#4936
@justinvp justinvp added the kind/enhancement Improvements or new features label Jul 23, 2024
@justinvp justinvp added this to the 0.108 milestone Jul 23, 2024
julienp added a commit to pulumi/docs that referenced this issue Jul 24, 2024
* Document Python Args and ArgsDict types

Document how in Python inputs can either be argument classes or
dictionary literals.

Ref pulumi/registry#4936

* Apply suggestions from code review

Co-authored-by: Justin Van Patten <[email protected]>

---------

Co-authored-by: Justin Van Patten <[email protected]>
julienp added a commit to pulumi/pulumi that referenced this issue Jul 30, 2024
In Python object inputs can either be argument classes or dictionary
literals. Link to the Python docs in the input section of the package
docs.

Fixes pulumi/registry#4936
julienp added a commit to pulumi/pulumi that referenced this issue Jul 30, 2024
In Python object inputs can either be argument classes or dictionary
literals. Link to the Python docs in the input section of the package
docs.

Fixes pulumi/registry#4936
@julienp
Copy link
Author

julienp commented Jul 30, 2024

Showing the Union really clutters up the docs, without giving useful information to the user (nowhere do we show the actual types of the union).

Instead of the clutter, we link to the python docs about inputs at the top of the section pulumi/pulumi#16763

github-merge-queue bot pushed a commit to pulumi/pulumi that referenced this issue Jul 31, 2024
In Python object inputs can either be argument classes or dictionary
literals. Link to the [Python input
docs](https://www.pulumi.com/docs/languages-sdks/python/#inputs-and-outputs)
in the input section of the package docs when the current language is
python.

Fixes pulumi/registry#4936

<img width="738" alt="Screenshot 2024-07-30 at 18 23 53"
src="https://github.com/user-attachments/assets/3ad00f45-a81d-4c2d-b3ad-f9ae811735f6">
@github-project-automation github-project-automation bot moved this from 🧳 Backlog to 🏁 Done in Docs 📚 Jul 31, 2024
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features language/python resolution/fixed This issue was fixed
Projects
Status: 🏁 Done
Development

Successfully merging a pull request may close this issue.

3 participants