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

Ignoring field names equal to reserved keywords like "from" #553

Closed
devgomax opened this issue Aug 11, 2023 · 1 comment
Closed

Ignoring field names equal to reserved keywords like "from" #553

devgomax opened this issue Aug 11, 2023 · 1 comment

Comments

@devgomax
Copy link

Hello! Here is the proto message for example:

message Range {
    google.protobuf.FloatValue from = 1;
    google.protobuf.FloatValue to = 2;
}

And there is the generated interface:

class Range(Message):
    DESCRIPTOR: Descriptor
    FROM_FIELD_NUMBER: int
    TO_FIELD_NUMBER: int
    @property
    def to(self) -> FloatValue: ...
    def __init__(self,
        *,
        to: Optional[FloatValue] = ...,
    ) -> None: ...
    def HasField(self, field_name: Literal["from",b"from","to",b"to"]) -> bool: ...
    def ClearField(self, field_name: Literal["from",b"from","to",b"to"]) -> None: ...

Unfortunately, generated model has no field named from.
So I have two questions:

  1. How can I get/set this field while initialization of the model Range?
  2. Is there any workaround for such fields?

Thanks in advance!

@devgomax devgomax changed the title Ignoring filed names equal to reserved keywords like "from" Ignoring field names equal to reserved keywords like "from" Aug 12, 2023
@nipunn1313
Copy link
Owner

Hi. from is a python reserved keyword so it is skipped on the property. You will have to use some methods from the base class - the getattr and setattr

See this for details
protocolbuffers/protobuf#3871

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants