fix: support pydantic-version google pb (#568)

* feat: pydantic version of google pb

* fix: patch pb Struct to support json, dict rountrip

* fix: pydantic-version google pb, json, dict rntrip

* chore: remove `@generated`, remove gen, code fmt

* chore: test case for pydantic-version google pb
This commit is contained in:
Maple
2024-04-09 05:54:36 +07:00
committed by GitHub
parent df1ba911b7
commit c3c20556e0
16 changed files with 5606 additions and 1869 deletions

View File

@@ -43,7 +43,12 @@ def parse_source_type_name(field_type_name: str) -> Tuple[str, str]:
def get_type_reference(
*, package: str, imports: set, source_type: str, unwrap: bool = True
*,
package: str,
imports: set,
source_type: str,
unwrap: bool = True,
pydantic: bool = False,
) -> str:
"""
Return a Python type name for a proto type reference. Adds the import if
@@ -69,7 +74,9 @@ def get_type_reference(
compiling_google_protobuf = current_package == ["google", "protobuf"]
importing_google_protobuf = py_package == ["google", "protobuf"]
if importing_google_protobuf and not compiling_google_protobuf:
py_package = ["betterproto", "lib"] + py_package
py_package = (
["betterproto", "lib"] + (["pydantic"] if pydantic else []) + py_package
)
if py_package[:1] == ["betterproto"]:
return reference_absolute(imports, py_package, py_type)