-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement flat-name container support
Summary: Implement support for flat-name containers in py3 auto-migrate. Previously, `import List__i32 from foo.types` would hard crash. Now it returns a class based loosely on `python.types.ListTypeFactory(typeinfo_i32)`. The class extends `python.types.List` and supplies the necessary `typeinfo` to properly construct `List`. It forwards the values, whether passed as `args` or `kwargs`. The class uses a `metaclass` that implements `__instancecheck__` so that customer `isinstance(x, List__i32)` will work properly even in auto-migrate. Reviewed By: prakashgayasen, Filip-F Differential Revision: D66985311 fbshipit-source-id: f4aa70084676f0617daa17768069f2df85080718
- Loading branch information
1 parent
3acd126
commit 8c09d66
Showing
10 changed files
with
865 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
thrift/compiler/generate/templates/py3/types/container_base.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{{! | ||
Copyright (c) Meta Platforms, Inc. and affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
}}{{! | ||
This is used only in py3 auto-migrate for the base class | ||
of flat-name containers (List__i32) | ||
}}{{#type:list?}}List{{/type:list?}}{{! | ||
}}{{#type:set?}}Set{{/type:set?}}{{! | ||
}}{{#type:map?}}Map{{/type:map?}} |
42 changes: 42 additions & 0 deletions
42
thrift/compiler/generate/templates/py3/types/typeinfo.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{{! | ||
Copyright (c) Meta Platforms, Inc. and affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
}}{{! | ||
This is used only in py3 auto-migrate to generate | ||
aliases for container flat names, i.e., List__i32 | ||
}}{{#type:bool?}}_fbthrift_python_types.typeinfo_bool{{/type:bool?}}{{! | ||
}}{{#type:byte?}}_fbthrift_python_types.typeinfo_byte{{/type:byte?}}{{! | ||
}}{{#type:i16?}}_fbthrift_python_types.typeinfo_i16{{/type:i16?}}{{! | ||
}}{{#type:i32?}}_fbthrift_python_types.typeinfo_i32{{/type:i32?}}{{! | ||
}}{{#type:i64?}}_fbthrift_python_types.typeinfo_i64{{/type:i64?}}{{! | ||
}}{{#type:double?}}_fbthrift_python_types.typeinfo_double{{/type:double?}}{{! | ||
}}{{#type:float?}}_fbthrift_python_types.typeinfo_float{{/type:float?}}{{! | ||
}}{{#type:string?}}_fbthrift_python_types.typeinfo_string{{/type:string?}}{{! | ||
}}{{#type:binary?}}{{#type:iobuf?}}_fbthrift_python_types.typeinfo_iobuf{{/type:iobuf?}}{{^type:iobuf?}}_fbthrift_python_types.typeinfo_binary{{/type:iobuf?}}{{/type:binary?}}{{! | ||
}}{{#type:struct}}_fbthrift_python_types.StructTypeInfo({{! | ||
}}{{type:module_auto_migrate_path}}.{{struct:name}}){{! | ||
}}{{/type:struct}}{{! | ||
}}{{#type:list?}}_fbthrift_python_types.ListTypeInfo({{#type:list_elem_type}}{{> types/typeinfo }}{{/type:list_elem_type}}){{/type:list?}}{{! | ||
}}{{#type:set?}}_fbthrift_python_types.SetTypeInfo({{#type:set_elem_type}}{{> types/typeinfo }}{{/type:set_elem_type}}){{/type:set?}}{{! | ||
}}{{#type:map?}}_fbthrift_python_types.MapTypeInfo({{! | ||
}}{{#type:key_type}}{{> types/typeinfo }}{{/type:key_type}}, {{! | ||
}}{{#type:value_type}}{{> types/typeinfo }}{{/type:value_type}}{{! | ||
}}){{/type:map?}}{{! | ||
}}{{#type:enum}}_fbthrift_python_types.EnumTypeInfo({{! | ||
}}{{type:module_auto_migrate_path}}.{{enum:name}}){{! | ||
}}{{/type:enum}} |
Oops, something went wrong.