Skip to content

Commit

Permalink
Add _to_mutable_python() to py-deprecated types.
Browse files Browse the repository at this point in the history
Reviewed By: yoney

Differential Revision: D66855542

fbshipit-source-id: 296fb910244ec8b6b28a3047837254fa06f80154
  • Loading branch information
Aristidis Papaioannou authored and facebook-github-bot committed Dec 6, 2024
1 parent 556de86 commit 9597f10
Show file tree
Hide file tree
Showing 104 changed files with 5,247 additions and 0 deletions.
14 changes: 14 additions & 0 deletions third-party/thrift/src/thrift/compiler/generate/t_py_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,20 @@ void t_py_generator::generate_py_converter_helpers(
<< endl;
indent_down();

out << indent() << "def _to_mutable_python(self):" << endl;
indent_up();
out << indent() << "import importlib" << endl
<< indent() << "import thrift.python.mutable_converter" << endl
<< indent() << "python_mutable_types = importlib.import_module(\""
<< python_namespace << ".thrift_mutable_types\")" << endl
<< indent() << "return "
<< "thrift.python.mutable_converter.to_mutable_python_struct_or_union("
<< "python_mutable_types."
<< rename_reserved_keywords(tstruct->get_name()) << ", self" << ")"
<< endl
<< endl;
indent_down();

auto py3_namespace = get_py3_namespace_with_name_and_prefix(program_, "");
out << indent() << "def _to_py3(self):" << endl;
indent_up();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class {{struct:name}}{{#struct:exception?}}(Thrift.TException){{/struct:exceptio
def __dir__(self) -> __T.Sequence[str]: ...
{{!TODO: accommodate root_module_prefix}}
def _to_python(self) -> "{{#program:pythonNamespaces}}{{value}}.{{/program:pythonNamespaces}}{{program:name}}.thrift_types.{{struct:name}}": ... # type: ignore
def _to_mutable_python(self) -> "{{#program:pythonNamespaces}}{{value}}.{{/program:pythonNamespaces}}{{program:name}}.thrift_mutable_types.{{struct:name}}": ... # type: ignore
def _to_py3(self) -> "{{#program:py3Namespaces}}{{value}}.{{/program:py3Namespaces}}{{program:name}}.types.{{struct:name}}": ... # type: ignore
def _to_py_deprecated(self) -> {{struct:name}}: ...
{{/program:structs}}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Name, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Name, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -353,6 +359,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Type, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Type, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -479,6 +491,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Ref, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Ref, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -607,6 +625,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Lazy, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Lazy, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -698,6 +722,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.DisableLazyChecksum, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.DisableLazyChecksum, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -924,6 +954,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Adapter, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Adapter, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1040,6 +1076,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.PackIsset, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.PackIsset, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1158,6 +1200,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.MinimizePadding, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.MinimizePadding, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1249,6 +1297,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.ScopedEnumAsUnionType, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.ScopedEnumAsUnionType, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1403,6 +1457,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.FieldInterceptor, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.FieldInterceptor, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1494,6 +1554,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.UseOpEncode, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.UseOpEncode, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1630,6 +1696,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.EnumType, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.EnumType, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1724,6 +1796,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Frozen2Exclude, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Frozen2Exclude, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1819,6 +1897,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Frozen2RequiresCompleteContainerParams, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Frozen2RequiresCompleteContainerParams, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1921,6 +2005,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.ProcessInEbThreadUnsafe, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.ProcessInEbThreadUnsafe, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -2015,6 +2105,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.RuntimeAnnotation, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.RuntimeAnnotation, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -2112,6 +2208,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.UseCursorSerialization, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.UseCursorSerialization, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -2220,6 +2322,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_types")
return thrift.python.converter.to_python_struct(python_types.GenerateDeprecatedHeaderClientMethods, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.cpp.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.GenerateDeprecatedHeaderClientMethods, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.FieldWrapper, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.FieldWrapper, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -324,6 +330,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Wrapper, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Wrapper, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -469,6 +481,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Adapter, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Adapter, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -581,6 +599,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.SkipCodegen, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.SkipCodegen, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -715,6 +739,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Name, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Name, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -844,6 +874,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.UnionEnumAttributes, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.UnionEnumAttributes, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -958,6 +994,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.StructTrait, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.StructTrait, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1125,6 +1167,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.Attributes, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.Attributes, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1216,6 +1264,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.StructAsTrait, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.StructAsTrait, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down Expand Up @@ -1310,6 +1364,12 @@ def _to_python(self):
python_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_types")
return thrift.python.converter.to_python_struct(python_types.ModuleInternal, self)

def _to_mutable_python(self):
import importlib
import thrift.python.mutable_converter
python_mutable_types = importlib.import_module("facebook.thrift.annotation.hack.thrift_mutable_types")
return thrift.python.mutable_converter.to_mutable_python_struct_or_union(python_mutable_types.ModuleInternal, self)

def _to_py3(self):
import importlib
import thrift.py3.converter
Expand Down
Loading

0 comments on commit 9597f10

Please sign in to comment.