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

Support to_dict for MapComposite #437

Open
dizcology opened this issue Mar 12, 2024 · 0 comments
Open

Support to_dict for MapComposite #437

dizcology opened this issue Mar 12, 2024 · 0 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@dizcology
Copy link

Is your feature request related to a problem? Please describe.

It is not obvious how to turn certain proto-plus types to Python dict.

Describe the solution you'd like

If x is an instance of a proto-plus type, x.to_dict() is a Python dict representation of it.

Additional context

As an example:

import proto
from google.cloud import dialogflowcx_v3beta1 as df

qr = df.QueryResult(parameters={'some_key': 'some_value'})

print(type(qr.parameters))  # proto.marshal.collections.maps.MapComposite

dict(qr.parameters)  # this works, but not intuitive.

qr.parameters.to_dict()  # no such method!

proto.Message.to_dict(qr)  # this works, but not intuitive.

qr.to_dict()  # no such method!

Bonus, continuing:

print(dict(qr.parameters))  # {'some_key': 'some_value'}, good!

print(dict(qr.parameters.pb)  # {'some_key': string_value: "some_value"}, huh?
@dizcology dizcology added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p3 Desirable enhancement or fix. May not be included in next release. labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

1 participant