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

Question about the MessageMeta.to_dict() function return type annotated as Message #489

Open
brendan-corrigan opened this issue Sep 28, 2024 · 0 comments
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@brendan-corrigan
Copy link

brendan-corrigan commented Sep 28, 2024

Currently calling Message.to_dict(my_message) and it is correctly returning a dictionary. However the my type checker is throwing errors downstream because it thinks it is a Message object instead of a python dict.

After looking through the source i found that the to_dict return type annotation is a Message:

def to_dict(
    cls,
    instance,
    *,
    use_integers_for_enums=True,
    preserving_proto_field_name=True,
    including_default_value_fields=None,
    float_precision=None,
    always_print_fields_with_no_presence=None,
) -> "Message":
        """Given a message instance, return its representation as a python dict.

However, the to_json method it is correctly typed as a str:

def to_json(
    cls,
    instance,
    *,
    use_integers_for_enums=True,
    including_default_value_fields=None,
    preserving_proto_field_name=False,
    sort_keys=False,
    indent=2,
    float_precision=None,
    always_print_fields_with_no_presence=None,
) -> str:

Wondering if this is the intended implementation?

@brendan-corrigan brendan-corrigan added priority: p3 Desirable enhancement or fix. May not be included in next release. type: question Request for information or clarification. Not an issue. labels Sep 28, 2024
@brendan-corrigan brendan-corrigan changed the title Question about the MessageMeta.to_dict() function return type annotated as Message Question about the MessageMeta.to_dict() function return type annotated as Message Sep 28, 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: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

1 participant