-
Notifications
You must be signed in to change notification settings - Fork 229
Importing well known types #9
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
Comments
It looks like the As a workaround you can define your own empty message until this is done. |
Howdy people! The same issue happens when I tried to use
The proto file has the following message
And the generated python class is import betterproto
from . import commons
from .google import protobuf
@dataclass
class Nugget(betterproto.Message):
qe_alerts: List[protobuf.Struct] = betterproto.message_field(1) |
There is a |
@devova yes but there are no generated dataclasses. I made this module as a bandaid. # proto_types.py
from dataclasses import dataclass
import betterproto
from google.protobuf import struct_pb2
@dataclass
class Struct(betterproto.Message):
def parse(self: betterproto.T, data: bytes) -> betterproto.T:
decoded = struct_pb2.Struct.FromString(data)
self.__dict__.update({item: value for item, value in decoded.items()})
return self
def __repr__(self):
return repr(self.__dict__)
@dataclass
class Empty(betterproto.Message):
def parse(self: betterproto.T, data: bytes) -> betterproto.T:
return self And then a post-generating find and replace. with open(file_path, 'r') as f:
lines = f.readlines()
with open(file_path, 'w') as f:
for line in lines:
line = line.replace("from .google import protobuf", "from wherever_proto_types_exists import proto_types")
line = line.replace('protobuf.Empty', 'proto_types.Empty')
line = line.replace('protobuf.Struct', 'proto_types.Struct')
f.write(line) where |
Fixed by #78? |
Not Even easier than the find-replace that @adisunw provides above, if you just put that file in |
Is this what is needed? (along with the other types) |
I am also impacted by this issue. |
Is this still an issue? I am using wkt timestamp and it works for me with 2.0.0b5. |
Seems like it's still an issue. The lack of support for |
wait, seems like all of them are already here 🤔
Any idea why there's no files under |
Hello,
I'm not sure how to work with well known types.
Having a proto file like this:
I get output like this:
There is ofcourse no
google
package. I tried to generate code from proto files included ingrpc_tools
but I'm not able to get any python code.What is the best way to work with well known types?
The text was updated successfully, but these errors were encountered: