diff --git a/thrift/compiler/generate/templates/py3/types/make_instance.mustache b/thrift/compiler/generate/templates/py3/types/make_instance.mustache index 3b0d261d353..ad59335c424 100644 --- a/thrift/compiler/generate/templates/py3/types/make_instance.mustache +++ b/thrift/compiler/generate/templates/py3/types/make_instance.mustache @@ -22,6 +22,12 @@ between types.pyx (default mode) and converters.pyx (auto-migrate mode) }} cdef {{> types/cython_cpp_type}} c_inst + {{#type:set?}}{{#type:set_elem_type}} + cdef {{> types/cython_cpp_type}} c_item + {{/type:set_elem_type}}{{/type:set?}} + {{#type:map?}}{{#type:key_type}} + cdef {{> types/cython_cpp_type}} c_key + {{/type:key_type}}{{/type:map?}} if items is None: return cmove(c_inst) {{^type:map?}} @@ -62,10 +68,13 @@ between types.pyx (default mode) and converters.pyx (auto-migrate mode) raise TypeError(f"{item!r} is not of type {{> types/pep484_type}}") {{#type:integer?}} {{! inject cython int overflow checks }} - item = <{{> types/cython_python_type}}> item + c_item = <{{> types/cython_python_type}}> item {{/type:integer?}} {{/type:container?}} - c_inst.insert({{> types/cython_python_to_cpp_item}}) + {{^type:integer?}} + c_item = {{> types/cython_python_to_cpp_item}} + {{/type:integer?}} + c_inst.insert(c_item) {{/type:set_elem_type}} {{/type:set?}} {{#type:map?}} @@ -82,9 +91,12 @@ between types.pyx (default mode) and converters.pyx (auto-migrate mode) raise TypeError(f"{key!r} is not of type {{> types/pep484_type}}") {{#type:integer?}} {{! inject cython int overflow checks }} - key = <{{> types/cython_python_type}}> key + c_key = <{{> types/cython_python_type}}> key {{/type:integer?}} {{/type:container?}} + {{^type:integer?}} + c_key = {{> types/cython_python_to_cpp_key}} + {{/type:integer?}} {{/type:key_type}} {{#type:value_type}} {{#type:container?}} @@ -103,9 +115,7 @@ between types.pyx (default mode) and converters.pyx (auto-migrate mode) {{/type:container?}} {{/type:value_type}} - c_inst[{{#type:key_type}}{{! - }}{{> types/cython_python_to_cpp_key}}{{/type:key_type}}{{! - }}] = {{#type:value_type}}{{! + c_inst[c_key] = {{#type:value_type}}{{! }}{{> types/cython_python_to_cpp_item}}{{/type:value_type}} {{/type:map?}} return cmove(c_inst) diff --git a/thrift/compiler/test/fixtures/basic-enum/out/py3/gen-py3/test/fixtures/enumstrict/module/types.pyx b/thrift/compiler/test/fixtures/basic-enum/out/py3/gen-py3/test/fixtures/enumstrict/module/types.pyx index 27559d220f5..1ad316c1249 100644 --- a/thrift/compiler/test/fixtures/basic-enum/out/py3/gen-py3/test/fixtures/enumstrict/module/types.pyx +++ b/thrift/compiler/test/fixtures/basic-enum/out/py3/gen-py3/test/fixtures/enumstrict/module/types.pyx @@ -198,15 +198,17 @@ cdef class MyStruct(thrift.py3.types.Struct): cdef cmap[_test_fixtures_enumstrict_module_cbindings.cMyEnum,string] Map__MyEnum_string__make_instance(object items) except *: cdef cmap[_test_fixtures_enumstrict_module_cbindings.cMyEnum,string] c_inst + cdef _test_fixtures_enumstrict_module_cbindings.cMyEnum c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, MyEnum): raise TypeError(f"{key!r} is not of type MyEnum") + c_key = <_test_fixtures_enumstrict_module_cbindings.cMyEnum>key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[<_test_fixtures_enumstrict_module_cbindings.cMyEnum>key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__MyEnum_string__from_cpp(const cmap[_test_fixtures_enumstrict_module_cbindings.cMyEnum,string]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/basic/out/py3/gen-py3/test/fixtures/basic/module/types.pyx b/thrift/compiler/test/fixtures/basic/out/py3/gen-py3/test/fixtures/basic/module/types.pyx index ac2419427b7..e75b25b0454 100644 --- a/thrift/compiler/test/fixtures/basic/out/py3/gen-py3/test/fixtures/basic/module/types.pyx +++ b/thrift/compiler/test/fixtures/basic/out/py3/gen-py3/test/fixtures/basic/module/types.pyx @@ -1233,12 +1233,14 @@ cdef class UnionToBeRenamed(thrift.py3.types.Union): cdef cset[float] Set__float__make_instance(object items) except *: cdef cset[float] c_inst + cdef float c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, (float, int)): raise TypeError(f"{item!r} is not of type float") - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__float__from_cpp(const cset[float]& c_set) except *: @@ -1270,6 +1272,7 @@ cdef object List__i32__from_cpp(const vector[cint32_t]& c_vec) except *: cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -1277,7 +1280,8 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__string__from_cpp(const cset[string]& c_set) except *: @@ -1291,16 +1295,18 @@ cdef object Set__string__from_cpp(const cset[string]& c_set) except *: cdef cmap[string,cint64_t] Map__string_i64__make_instance(object items) except *: cdef cmap[string,cint64_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i64__from_cpp(const cmap[string,cint64_t]& c_map) except *: @@ -1315,17 +1321,19 @@ cdef object Map__string_i64__from_cpp(const cmap[string,cint64_t]& c_map) except cdef cmap[string,vector[cint32_t]] Map__string_List__i32__make_instance(object items) except *: cdef cmap[string,vector[cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Sequence[int]") if not isinstance(item, List__i32): item = List__i32(item) - c_inst[key.encode('UTF-8')] = List__i32__make_instance(item) + c_inst[c_key] = List__i32__make_instance(item) return cmove(c_inst) cdef object Map__string_List__i32__from_cpp(const cmap[string,vector[cint32_t]]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/complex-union/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/complex-union/out/py3/gen-py3/module/types.pyx index 58a8d166a72..cdf07bcbeda 100644 --- a/thrift/compiler/test/fixtures/complex-union/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/complex-union/out/py3/gen-py3/module/types.pyx @@ -1378,16 +1378,17 @@ cdef object List__string__from_cpp(const vector[string]& c_vec) except *: cdef cmap[cint16_t,string] Map__i16_string__make_instance(object items) except *: cdef cmap[cint16_t,string] c_inst + cdef cint16_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__i16_string__from_cpp(const cmap[cint16_t,string]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/constants/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/constants/out/py3/gen-py3/module/types.pyx index c7fc4457458..8f60ba4faac 100644 --- a/thrift/compiler/test/fixtures/constants/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/constants/out/py3/gen-py3/module/types.pyx @@ -1320,16 +1320,18 @@ cdef object List__i32__from_cpp(const vector[cint32_t]& c_vec) except *: cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except *: @@ -1363,15 +1365,17 @@ cdef object List__Map__string_i32__from_cpp(const vector[cmap[string,cint32_t]]& cdef cmap[string,string] Map__string_string__make_instance(object items) except *: cdef cmap[string,string] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key.encode('UTF-8')] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__string_string__from_cpp(const cmap[string,string]& c_map) except *: @@ -1456,13 +1460,14 @@ cdef object List__string__from_cpp(const vector[string]& c_vec) except *: cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -1476,6 +1481,7 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -1483,7 +1489,8 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__string__from_cpp(const cset[string]& c_set) except *: @@ -1497,17 +1504,18 @@ cdef object Set__string__from_cpp(const cset[string]& c_set) except *: cdef cmap[cint32_t,cint32_t] Map__i32_i32__make_instance(object items) except *: cdef cmap[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_i32__from_cpp(const cmap[cint32_t,cint32_t]& c_map) except *: @@ -1522,16 +1530,17 @@ cdef object Map__i32_i32__from_cpp(const cmap[cint32_t,cint32_t]& c_map) except cdef cmap[cint32_t,string] Map__i32_string__make_instance(object items) except *: cdef cmap[cint32_t,string] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__i32_string__from_cpp(const cmap[cint32_t,string]& c_map) except *: @@ -1546,16 +1555,17 @@ cdef object Map__i32_string__from_cpp(const cmap[cint32_t,string]& c_map) except cdef cmap[cint32_t,cbool] Map__i32_bool__make_instance(object items) except *: cdef cmap[cint32_t,cbool] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, bool): raise TypeError(f"{item!r} is not of type bool") - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_bool__from_cpp(const cmap[cint32_t,cbool]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/enums/out/py3/gen-py3/test/fixtures/enums/module/types.pyx b/thrift/compiler/test/fixtures/enums/out/py3/gen-py3/test/fixtures/enums/module/types.pyx index 7b2123cb9f0..4d6109b87ec 100644 --- a/thrift/compiler/test/fixtures/enums/out/py3/gen-py3/test/fixtures/enums/module/types.pyx +++ b/thrift/compiler/test/fixtures/enums/out/py3/gen-py3/test/fixtures/enums/module/types.pyx @@ -368,13 +368,14 @@ cdef class MyStruct(thrift.py3.types.Struct): cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: diff --git a/thrift/compiler/test/fixtures/list/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/list/out/py3/gen-py3/module/types.pyx index 1ce2f570df1..7c38d98e6c4 100644 --- a/thrift/compiler/test/fixtures/list/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/list/out/py3/gen-py3/module/types.pyx @@ -85,18 +85,19 @@ cdef object List__string__from_cpp(const vector[string]& c_vec) except *: cdef cmap[cint64_t,vector[string]] Map__i64_List__string__make_instance(object items) except *: cdef cmap[cint64_t,vector[string]] c_inst + cdef cint64_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if item is None: raise TypeError("None is not of type _typing.Sequence[str]") if not isinstance(item, List__string): item = List__string(item) - c_inst[key] = List__string__make_instance(item) + c_inst[c_key] = List__string__make_instance(item) return cmove(c_inst) cdef object Map__i64_List__string__from_cpp(const cmap[cint64_t,vector[string]]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/mcpp2-compare/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/mcpp2-compare/out/py3/gen-py3/module/types.pyx index 226e0e1d59b..ff6f762e92f 100644 --- a/thrift/compiler/test/fixtures/mcpp2-compare/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/mcpp2-compare/out/py3/gen-py3/module/types.pyx @@ -3677,16 +3677,18 @@ cdef class AllRequiredNoExceptMoveCtrStruct(thrift.py3.types.Struct): cdef cmap[string,cint64_t] Map__string_i64__make_instance(object items) except *: cdef cmap[string,cint64_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i64__from_cpp(const cmap[string,cint64_t]& c_map) except *: @@ -3701,15 +3703,17 @@ cdef object Map__string_i64__from_cpp(const cmap[string,cint64_t]& c_map) except cdef cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct] Map__Empty_MyStruct__make_instance(object items) except *: cdef cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct] c_inst + cdef _module_cbindings.cEmpty c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, Empty): raise TypeError(f"{key!r} is not of type Empty") + c_key = deref((key)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) if not isinstance(item, MyStruct): raise TypeError(f"{item!r} is not of type MyStruct") - c_inst[deref((key)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst[c_key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) return cmove(c_inst) cdef object Map__Empty_MyStruct__from_cpp(const cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct]& c_map) except *: @@ -3798,12 +3802,14 @@ cdef object List__MyEnumA__from_cpp(const vector[_module_cbindings.cMyEnumA]& c_ cdef cset[_module_cbindings.cMyStruct] Set__MyStruct__make_instance(object items) except *: cdef cset[_module_cbindings.cMyStruct] c_inst + cdef _module_cbindings.cMyStruct c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, MyStruct): raise TypeError(f"{item!r} is not of type MyStruct") - c_inst.insert(deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + c_item = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__MyStruct__from_cpp(const cset[_module_cbindings.cMyStruct]& c_set) except *: @@ -3853,6 +3859,7 @@ cdef object List__string__from_cpp(const vector[string]& c_vec) except *: cdef cset[vector[string]] Set__List__string__make_instance(object items) except *: cdef cset[vector[string]] c_inst + cdef vector[string] c_item if items is None: return cmove(c_inst) for item in items: @@ -3860,7 +3867,8 @@ cdef cset[vector[string]] Set__List__string__make_instance(object items) except raise TypeError("None is not of type _typing.Sequence[str]") if not isinstance(item, List__string): item = List__string(item) - c_inst.insert(List__string__make_instance(item)) + c_item = List__string__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__List__string__from_cpp(const cset[vector[string]]& c_set) except *: @@ -3874,6 +3882,7 @@ cdef object Set__List__string__from_cpp(const cset[vector[string]]& c_set) excep cdef cset[vector[vector[cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct]]]] Set__List__List__Map__Empty_MyStruct__make_instance(object items) except *: cdef cset[vector[vector[cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct]]]] c_inst + cdef vector[vector[cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct]]] c_item if items is None: return cmove(c_inst) for item in items: @@ -3881,7 +3890,8 @@ cdef cset[vector[vector[cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruc raise TypeError("None is not of type _typing.Sequence[_typing.Sequence[_typing.Mapping[Empty, MyStruct]]]") if not isinstance(item, List__List__Map__Empty_MyStruct): item = List__List__Map__Empty_MyStruct(item) - c_inst.insert(List__List__Map__Empty_MyStruct__make_instance(item)) + c_item = List__List__Map__Empty_MyStruct__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__List__List__Map__Empty_MyStruct__from_cpp(const cset[vector[vector[cmap[_module_cbindings.cEmpty,_module_cbindings.cMyStruct]]]]& c_set) except *: @@ -3895,18 +3905,19 @@ cdef object Set__List__List__Map__Empty_MyStruct__from_cpp(const cset[vector[vec cdef cmap[cint32_t,vector[string]] Map__i32_List__string__make_instance(object items) except *: cdef cmap[cint32_t,vector[string]] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if item is None: raise TypeError("None is not of type _typing.Sequence[str]") if not isinstance(item, List__string): item = List__string(item) - c_inst[key] = List__string__make_instance(item) + c_inst[c_key] = List__string__make_instance(item) return cmove(c_inst) cdef object Map__i32_List__string__from_cpp(const cmap[cint32_t,vector[string]]& c_map) except *: @@ -4013,6 +4024,7 @@ cdef object List__List__List__List__i32__from_cpp(const vector[vector[vector[vec cdef cset[vector[cint32_t]] Set__List__i32__make_instance(object items) except *: cdef cset[vector[cint32_t]] c_inst + cdef vector[cint32_t] c_item if items is None: return cmove(c_inst) for item in items: @@ -4020,7 +4032,8 @@ cdef cset[vector[cint32_t]] Set__List__i32__make_instance(object items) except * raise TypeError("None is not of type _typing.Sequence[int]") if not isinstance(item, List__i32): item = List__i32(item) - c_inst.insert(List__i32__make_instance(item)) + c_item = List__i32__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__List__i32__from_cpp(const cset[vector[cint32_t]]& c_set) except *: @@ -4034,6 +4047,7 @@ cdef object Set__List__i32__from_cpp(const cset[vector[cint32_t]]& c_set) except cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -4041,7 +4055,8 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__string__from_cpp(const cset[string]& c_set) except *: @@ -4074,6 +4089,7 @@ cdef object List__Set__string__from_cpp(const vector[cset[string]]& c_vec) excep cdef cmap[vector[cset[string]],string] Map__List__Set__string_string__make_instance(object items) except *: cdef cmap[vector[cset[string]],string] c_inst + cdef vector[cset[string]] c_key if items is None: return cmove(c_inst) for key, item in items.items(): @@ -4081,10 +4097,11 @@ cdef cmap[vector[cset[string]],string] Map__List__Set__string_string__make_insta raise TypeError("None is not of type _typing.Sequence[_typing.AbstractSet[str]]") if not isinstance(key, List__Set__string): key = List__Set__string(key) + c_key = List__Set__string__make_instance(key) if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[List__Set__string__make_instance(key)] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__List__Set__string_string__from_cpp(const cmap[vector[cset[string]],string]& c_map) except *: @@ -4099,6 +4116,7 @@ cdef object Map__List__Set__string_string__from_cpp(const cmap[vector[cset[strin cdef cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]] Map__Set__List__i32_Map__List__Set__string_string__make_instance(object items) except *: cdef cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]] c_inst + cdef cset[vector[cint32_t]] c_key if items is None: return cmove(c_inst) for key, item in items.items(): @@ -4106,12 +4124,13 @@ cdef cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]] Map__Set__Li raise TypeError("None is not of type _typing.AbstractSet[_typing.Sequence[int]]") if not isinstance(key, Set__List__i32): key = Set__List__i32(key) + c_key = Set__List__i32__make_instance(key) if item is None: raise TypeError("None is not of type _typing.Mapping[_typing.Sequence[_typing.AbstractSet[str]], str]") if not isinstance(item, Map__List__Set__string_string): item = Map__List__Set__string_string(item) - c_inst[Set__List__i32__make_instance(key)] = Map__List__Set__string_string__make_instance(item) + c_inst[c_key] = Map__List__Set__string_string__make_instance(item) return cmove(c_inst) cdef object Map__Set__List__i32_Map__List__Set__string_string__from_cpp(const cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]]& c_map) except *: @@ -4145,15 +4164,17 @@ cdef object List__binary__from_cpp(const vector[string]& c_vec) except *: cdef cmap[_module_cbindings.cMyEnumA,string] Map__MyEnumA_string__make_instance(object items) except *: cdef cmap[_module_cbindings.cMyEnumA,string] c_inst + cdef _module_cbindings.cMyEnumA c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, MyEnumA): raise TypeError(f"{key!r} is not of type MyEnumA") + c_key = <_module_cbindings.cMyEnumA>key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[<_module_cbindings.cMyEnumA>key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__MyEnumA_string__from_cpp(const cmap[_module_cbindings.cMyEnumA,string]& c_map) except *: @@ -4168,13 +4189,14 @@ cdef object Map__MyEnumA_string__from_cpp(const cmap[_module_cbindings.cMyEnumA, cdef cset[cint64_t] Set__i64__make_instance(object items) except *: cdef cset[cint64_t] c_inst + cdef cint64_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i64__from_cpp(const cset[cint64_t]& c_set) except *: @@ -4188,16 +4210,18 @@ cdef object Set__i64__from_cpp(const cset[cint64_t]& c_set) except *: cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except *: @@ -4229,12 +4253,14 @@ cdef object List__SimpleUnion__from_cpp(const vector[_module_cbindings.cSimpleUn cdef cset[_module_cbindings.cSimpleUnion] Set__SimpleUnion__make_instance(object items) except *: cdef cset[_module_cbindings.cSimpleUnion] c_inst + cdef _module_cbindings.cSimpleUnion c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, SimpleUnion): raise TypeError(f"{item!r} is not of type SimpleUnion") - c_inst.insert(deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE)) + c_item = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__SimpleUnion__from_cpp(const cset[_module_cbindings.cSimpleUnion]& c_set) except *: @@ -4267,15 +4293,17 @@ cdef object List__Set__SimpleUnion__from_cpp(const vector[cset[_module_cbindings cdef cmap[string,cbool] Map__string_bool__make_instance(object items) except *: cdef cmap[string,cbool] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, bool): raise TypeError(f"{item!r} is not of type bool") - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_bool__from_cpp(const cmap[string,cbool]& c_map) except *: @@ -4290,13 +4318,14 @@ cdef object Map__string_bool__from_cpp(const cmap[string,cbool]& c_map) except * cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -4310,17 +4339,19 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cmap[string,cmap[string,cint32_t]] Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, int]") if not isinstance(item, Map__string_i32): item = Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_i32__make_instance(item) return cmove(c_inst) cdef object Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string,cint32_t]]& c_map) except *: @@ -4335,17 +4366,19 @@ cdef object Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string, cdef cmap[string,cmap[string,cmap[string,cint32_t]]] Map__string_Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cmap[string,cint32_t]]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, _typing.Mapping[str, int]]") if not isinstance(item, Map__string_Map__string_i32): item = Map__string_Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_Map__string_i32__make_instance(item) return cmove(c_inst) cdef object Map__string_Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string,cmap[string,cint32_t]]]& c_map) except *: @@ -4379,17 +4412,19 @@ cdef object List__Set__i32__from_cpp(const vector[cset[cint32_t]]& c_vec) except cdef cmap[string,vector[cint32_t]] Map__string_List__i32__make_instance(object items) except *: cdef cmap[string,vector[cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Sequence[int]") if not isinstance(item, List__i32): item = List__i32(item) - c_inst[key.encode('UTF-8')] = List__i32__make_instance(item) + c_inst[c_key] = List__i32__make_instance(item) return cmove(c_inst) cdef object Map__string_List__i32__from_cpp(const cmap[string,vector[cint32_t]]& c_map) except *: @@ -4404,12 +4439,14 @@ cdef object Map__string_List__i32__from_cpp(const cmap[string,vector[cint32_t]]& cdef cset[cbool] Set__bool__make_instance(object items) except *: cdef cset[cbool] c_inst + cdef cbool c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, bool): raise TypeError(f"{item!r} is not of type bool") - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__bool__from_cpp(const cset[cbool]& c_set) except *: @@ -4423,6 +4460,7 @@ cdef object Set__bool__from_cpp(const cset[cbool]& c_set) except *: cdef cset[cset[cbool]] Set__Set__bool__make_instance(object items) except *: cdef cset[cset[cbool]] c_inst + cdef cset[cbool] c_item if items is None: return cmove(c_inst) for item in items: @@ -4430,7 +4468,8 @@ cdef cset[cset[cbool]] Set__Set__bool__make_instance(object items) except *: raise TypeError("None is not of type _typing.AbstractSet[bool]") if not isinstance(item, Set__bool): item = Set__bool(item) - c_inst.insert(Set__bool__make_instance(item)) + c_item = Set__bool__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__Set__bool__from_cpp(const cset[cset[cbool]]& c_set) except *: @@ -4444,6 +4483,7 @@ cdef object Set__Set__bool__from_cpp(const cset[cset[cbool]]& c_set) except *: cdef cset[cset[cset[cbool]]] Set__Set__Set__bool__make_instance(object items) except *: cdef cset[cset[cset[cbool]]] c_inst + cdef cset[cset[cbool]] c_item if items is None: return cmove(c_inst) for item in items: @@ -4451,7 +4491,8 @@ cdef cset[cset[cset[cbool]]] Set__Set__Set__bool__make_instance(object items) ex raise TypeError("None is not of type _typing.AbstractSet[_typing.AbstractSet[bool]]") if not isinstance(item, Set__Set__bool): item = Set__Set__bool(item) - c_inst.insert(Set__Set__bool__make_instance(item)) + c_item = Set__Set__bool__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__Set__Set__bool__from_cpp(const cset[cset[cset[cbool]]]& c_set) except *: @@ -4465,16 +4506,18 @@ cdef object Set__Set__Set__bool__from_cpp(const cset[cset[cset[cbool]]]& c_set) cdef cmap[_module_cbindings.Bar,_module_cbindings.Baz] Map__Bar__double_Baz__i32__make_instance(object items) except *: cdef cmap[_module_cbindings.Bar,_module_cbindings.Baz] c_inst + cdef _module_cbindings.Bar c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, (float, int)): raise TypeError(f"{key!r} is not of type float") + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__Bar__double_Baz__i32__from_cpp(const cmap[_module_cbindings.Bar,_module_cbindings.Baz]& c_map) except *: @@ -4507,6 +4550,7 @@ cdef object folly_small_vector_int64_t_8__List__i64__from_cpp(const _module_cbin cdef _module_cbindings.folly_sorted_vector_set_std_string folly_sorted_vector_set_std_string__Set__string__make_instance(object items) except *: cdef _module_cbindings.folly_sorted_vector_set_std_string c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -4514,7 +4558,8 @@ cdef _module_cbindings.folly_sorted_vector_set_std_string folly_sorted_vector_se for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object folly_sorted_vector_set_std_string__Set__string__from_cpp(const _module_cbindings.folly_sorted_vector_set_std_string& c_set) except *: @@ -4528,16 +4573,17 @@ cdef object folly_sorted_vector_set_std_string__Set__string__from_cpp(const _mod cdef _module_cbindings.FakeMap FakeMap__Map__i64_double__make_instance(object items) except *: cdef _module_cbindings.FakeMap c_inst + cdef cint64_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, (float, int)): raise TypeError(f"{item!r} is not of type float") - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object FakeMap__Map__i64_double__from_cpp(const _module_cbindings.FakeMap& c_map) except *: @@ -4552,15 +4598,17 @@ cdef object FakeMap__Map__i64_double__from_cpp(const _module_cbindings.FakeMap& cdef _module_cbindings.std_unordered_map_std_string_containerStruct std_unordered_map_std_string_containerStruct__Map__string_containerStruct__make_instance(object items) except *: cdef _module_cbindings.std_unordered_map_std_string_containerStruct c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, containerStruct): raise TypeError(f"{item!r} is not of type containerStruct") - c_inst[key.encode('UTF-8')] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst[c_key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) return cmove(c_inst) cdef object std_unordered_map_std_string_containerStruct__Map__string_containerStruct__from_cpp(const _module_cbindings.std_unordered_map_std_string_containerStruct& c_map) except *: @@ -4612,6 +4660,7 @@ cdef object std_deque__List__string__from_cpp(const _module_cbindings.std_deque[ cdef _module_cbindings.folly_sorted_vector_set[string] folly_sorted_vector_set__Set__string__make_instance(object items) except *: cdef _module_cbindings.folly_sorted_vector_set[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -4619,7 +4668,8 @@ cdef _module_cbindings.folly_sorted_vector_set[string] folly_sorted_vector_set__ for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object folly_sorted_vector_set__Set__string__from_cpp(const _module_cbindings.folly_sorted_vector_set[string]& c_set) except *: @@ -4633,16 +4683,17 @@ cdef object folly_sorted_vector_set__Set__string__from_cpp(const _module_cbindin cdef _module_cbindings.folly_sorted_vector_map[cint64_t,string] folly_sorted_vector_map__Map__i64_string__make_instance(object items) except *: cdef _module_cbindings.folly_sorted_vector_map[cint64_t,string] c_inst + cdef cint64_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object folly_sorted_vector_map__Map__i64_string__from_cpp(const _module_cbindings.folly_sorted_vector_map[cint64_t,string]& c_map) except *: @@ -4674,13 +4725,14 @@ cdef object List__Bar__double__from_cpp(const vector[_module_cbindings.Bar]& c_v cdef cset[_module_cbindings.Baz] Set__Baz__i32__make_instance(object items) except *: cdef cset[_module_cbindings.Baz] c_inst + cdef _module_cbindings.Baz c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__Baz__i32__from_cpp(const cset[_module_cbindings.Baz]& c_set) except *: @@ -4694,15 +4746,17 @@ cdef object Set__Baz__i32__from_cpp(const cset[_module_cbindings.Baz]& c_set) ex cdef cmap[string,_fbthrift_iobuf.cIOBuf] Map__string_folly_IOBuf__binary__make_instance(object items) except *: cdef cmap[string,_fbthrift_iobuf.cIOBuf] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, _fbthrift_iobuf.IOBuf): raise TypeError(f"{item!r} is not of type _fbthrift_iobuf.IOBuf") - c_inst[key.encode('UTF-8')] = deref((<_fbthrift_iobuf.IOBuf?>item).c_clone()) + c_inst[c_key] = deref((<_fbthrift_iobuf.IOBuf?>item).c_clone()) return cmove(c_inst) cdef object Map__string_folly_IOBuf__binary__from_cpp(const cmap[string,_fbthrift_iobuf.cIOBuf]& c_map) except *: @@ -4717,15 +4771,17 @@ cdef object Map__string_folly_IOBuf__binary__from_cpp(const cmap[string,_fbthrif cdef cmap[string,unique_ptr[_fbthrift_iobuf.cIOBuf]] Map__string_std_unique_ptr_folly_IOBuf__binary__make_instance(object items) except *: cdef cmap[string,unique_ptr[_fbthrift_iobuf.cIOBuf]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, _fbthrift_iobuf.IOBuf): raise TypeError(f"{item!r} is not of type _fbthrift_iobuf.IOBuf") - c_inst[key.encode('UTF-8')] = (<_fbthrift_iobuf.IOBuf?>item).c_clone() + c_inst[c_key] = (<_fbthrift_iobuf.IOBuf?>item).c_clone() return cmove(c_inst) cdef object Map__string_std_unique_ptr_folly_IOBuf__binary__from_cpp(const cmap[string,unique_ptr[_fbthrift_iobuf.cIOBuf]]& c_map) except *: @@ -4740,16 +4796,17 @@ cdef object Map__string_std_unique_ptr_folly_IOBuf__binary__from_cpp(const cmap[ cdef cmap[cint32_t,string] Map__i32_string__make_instance(object items) except *: cdef cmap[cint32_t,string] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__i32_string__from_cpp(const cmap[cint32_t,string]& c_map) except *: @@ -4783,16 +4840,17 @@ cdef object List__Map__string_i32__from_cpp(const vector[cmap[string,cint32_t]]& cdef cmap[cint16_t,string] Map__i16_string__make_instance(object items) except *: cdef cmap[cint16_t,string] c_inst + cdef cint16_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__i16_string__from_cpp(const cmap[cint16_t,string]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/optionals/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/optionals/out/py3/gen-py3/module/types.pyx index d505698fc24..c042a998f45 100644 --- a/thrift/compiler/test/fixtures/optionals/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/optionals/out/py3/gen-py3/module/types.pyx @@ -577,13 +577,14 @@ cdef class Person(thrift.py3.types.Struct): cdef cset[cint64_t] Set__i64__make_instance(object items) except *: cdef cset[cint64_t] c_inst + cdef cint64_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i64__from_cpp(const cset[cint64_t]& c_set) except *: @@ -597,15 +598,17 @@ cdef object Set__i64__from_cpp(const cset[cint64_t]& c_set) except *: cdef cmap[_module_cbindings.cAnimal,string] Map__Animal_string__make_instance(object items) except *: cdef cmap[_module_cbindings.cAnimal,string] c_inst + cdef _module_cbindings.cAnimal c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, Animal): raise TypeError(f"{key!r} is not of type Animal") + c_key = <_module_cbindings.cAnimal>key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[<_module_cbindings.cAnimal>key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__Animal_string__from_cpp(const cmap[_module_cbindings.cAnimal,string]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/params/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/params/out/py3/gen-py3/module/types.pyx index be17089c643..7a8d3ecc29d 100644 --- a/thrift/compiler/test/fixtures/params/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/params/out/py3/gen-py3/module/types.pyx @@ -92,18 +92,19 @@ cdef object List__i32__from_cpp(const vector[cint32_t]& c_vec) except *: cdef cmap[cint32_t,vector[cint32_t]] Map__i32_List__i32__make_instance(object items) except *: cdef cmap[cint32_t,vector[cint32_t]] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if item is None: raise TypeError("None is not of type _typing.Sequence[int]") if not isinstance(item, List__i32): item = List__i32(item) - c_inst[key] = List__i32__make_instance(item) + c_inst[c_key] = List__i32__make_instance(item) return cmove(c_inst) cdef object Map__i32_List__i32__from_cpp(const cmap[cint32_t,vector[cint32_t]]& c_map) except *: @@ -118,13 +119,14 @@ cdef object Map__i32_List__i32__from_cpp(const cmap[cint32_t,vector[cint32_t]]& cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -138,18 +140,19 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cmap[cint32_t,cset[cint32_t]] Map__i32_Set__i32__make_instance(object items) except *: cdef cmap[cint32_t,cset[cint32_t]] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if item is None: raise TypeError("None is not of type _typing.AbstractSet[int]") if not isinstance(item, Set__i32): item = Set__i32(item) - c_inst[key] = Set__i32__make_instance(item) + c_inst[c_key] = Set__i32__make_instance(item) return cmove(c_inst) cdef object Map__i32_Set__i32__from_cpp(const cmap[cint32_t,cset[cint32_t]]& c_map) except *: @@ -164,17 +167,18 @@ cdef object Map__i32_Set__i32__from_cpp(const cmap[cint32_t,cset[cint32_t]]& c_m cdef cmap[cint32_t,cint32_t] Map__i32_i32__make_instance(object items) except *: cdef cmap[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_i32__from_cpp(const cmap[cint32_t,cint32_t]& c_map) except *: @@ -227,18 +231,19 @@ cdef object List__Set__i32__from_cpp(const vector[cset[cint32_t]]& c_vec) except cdef cmap[cint32_t,cmap[cint32_t,cset[cint32_t]]] Map__i32_Map__i32_Set__i32__make_instance(object items) except *: cdef cmap[cint32_t,cmap[cint32_t,cset[cint32_t]]] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if item is None: raise TypeError("None is not of type _typing.Mapping[int, _typing.AbstractSet[int]]") if not isinstance(item, Map__i32_Set__i32): item = Map__i32_Set__i32(item) - c_inst[key] = Map__i32_Set__i32__make_instance(item) + c_inst[c_key] = Map__i32_Set__i32__make_instance(item) return cmove(c_inst) cdef object Map__i32_Map__i32_Set__i32__from_cpp(const cmap[cint32_t,cmap[cint32_t,cset[cint32_t]]]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/py3/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/py3/out/py3/gen-py3/module/types.pyx index 4d0c53f1577..4e2856ce262 100644 --- a/thrift/compiler/test/fixtures/py3/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/py3/out/py3/gen-py3/module/types.pyx @@ -1722,13 +1722,14 @@ cdef object List__SimpleStruct__from_cpp(const vector[_module_cbindings.cSimpleS cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -1742,6 +1743,7 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -1749,7 +1751,8 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__string__from_cpp(const cset[string]& c_set) except *: @@ -1763,15 +1766,17 @@ cdef object Set__string__from_cpp(const cset[string]& c_set) except *: cdef cmap[string,string] Map__string_string__make_instance(object items) except *: cdef cmap[string,string] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key.encode('UTF-8')] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__string_string__from_cpp(const cmap[string,string]& c_map) except *: @@ -1786,15 +1791,17 @@ cdef object Map__string_string__from_cpp(const cmap[string,string]& c_map) excep cdef cmap[string,_module_cbindings.cSimpleStruct] Map__string_SimpleStruct__make_instance(object items) except *: cdef cmap[string,_module_cbindings.cSimpleStruct] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, SimpleStruct): raise TypeError(f"{item!r} is not of type SimpleStruct") - c_inst[key.encode('UTF-8')] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst[c_key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) return cmove(c_inst) cdef object Map__string_SimpleStruct__from_cpp(const cmap[string,_module_cbindings.cSimpleStruct]& c_map) except *: @@ -1809,16 +1816,18 @@ cdef object Map__string_SimpleStruct__from_cpp(const cmap[string,_module_cbindin cdef cmap[string,cint16_t] Map__string_i16__make_instance(object items) except *: cdef cmap[string,cint16_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i16__from_cpp(const cmap[string,cint16_t]& c_map) except *: @@ -1852,16 +1861,18 @@ cdef object List__List__i32__from_cpp(const vector[vector[cint32_t]]& c_vec) exc cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except *: @@ -1876,17 +1887,19 @@ cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except cdef cmap[string,cmap[string,cint32_t]] Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, int]") if not isinstance(item, Map__string_i32): item = Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_i32__make_instance(item) return cmove(c_inst) cdef object Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string,cint32_t]]& c_map) except *: @@ -1920,17 +1933,19 @@ cdef object List__Set__string__from_cpp(const vector[cset[string]]& c_vec) excep cdef cmap[string,vector[_module_cbindings.cSimpleStruct]] Map__string_List__SimpleStruct__make_instance(object items) except *: cdef cmap[string,vector[_module_cbindings.cSimpleStruct]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Sequence[SimpleStruct]") if not isinstance(item, List__SimpleStruct): item = List__SimpleStruct(item) - c_inst[key.encode('UTF-8')] = List__SimpleStruct__make_instance(item) + c_inst[c_key] = List__SimpleStruct__make_instance(item) return cmove(c_inst) cdef object Map__string_List__SimpleStruct__from_cpp(const cmap[string,vector[_module_cbindings.cSimpleStruct]]& c_map) except *: @@ -2021,6 +2036,7 @@ cdef object List__binary__from_cpp(const vector[string]& c_vec) except *: cdef cset[string] Set__binary__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -2028,7 +2044,8 @@ cdef cset[string] Set__binary__make_instance(object items) except *: for item in items: if not isinstance(item, bytes): raise TypeError(f"{item!r} is not of type bytes") - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__binary__from_cpp(const cset[string]& c_set) except *: @@ -2059,17 +2076,18 @@ cdef object List__AnEnum__from_cpp(const vector[_module_cbindings.cAnEnum]& c_ve cdef _module_cbindings._std_unordered_map[cint32_t,cint32_t] _std_unordered_map__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._std_unordered_map[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object _std_unordered_map__Map__i32_i32__from_cpp(const _module_cbindings._std_unordered_map[cint32_t,cint32_t]& c_map) except *: @@ -2102,13 +2120,14 @@ cdef object _MyType__List__i32__from_cpp(const _module_cbindings._MyType& c_vec) cdef _module_cbindings._MyType _MyType__Set__i32__make_instance(object items) except *: cdef _module_cbindings._MyType c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object _MyType__Set__i32__from_cpp(const _module_cbindings._MyType& c_set) except *: @@ -2122,17 +2141,18 @@ cdef object _MyType__Set__i32__from_cpp(const _module_cbindings._MyType& c_set) cdef _module_cbindings._MyType _MyType__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._MyType c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object _MyType__Map__i32_i32__from_cpp(const _module_cbindings._MyType& c_map) except *: @@ -2165,13 +2185,14 @@ cdef object _py3_simple_AdaptedList__List__i32__from_cpp(const _module_cbindings cdef _module_cbindings._py3_simple_AdaptedSet _py3_simple_AdaptedSet__Set__i32__make_instance(object items) except *: cdef _module_cbindings._py3_simple_AdaptedSet c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object _py3_simple_AdaptedSet__Set__i32__from_cpp(const _module_cbindings._py3_simple_AdaptedSet& c_set) except *: @@ -2185,17 +2206,18 @@ cdef object _py3_simple_AdaptedSet__Set__i32__from_cpp(const _module_cbindings._ cdef _module_cbindings._py3_simple_AdaptedMap _py3_simple_AdaptedMap__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._py3_simple_AdaptedMap c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object _py3_simple_AdaptedMap__Map__i32_i32__from_cpp(const _module_cbindings._py3_simple_AdaptedMap& c_map) except *: @@ -2210,16 +2232,17 @@ cdef object _py3_simple_AdaptedMap__Map__i32_i32__from_cpp(const _module_cbindin cdef cmap[cint32_t,double] Map__i32_double__make_instance(object items) except *: cdef cmap[cint32_t,double] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, (float, int)): raise TypeError(f"{item!r} is not of type float") - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_double__from_cpp(const cmap[cint32_t,double]& c_map) except *: @@ -2253,16 +2276,18 @@ cdef object List__Map__i32_double__from_cpp(const vector[cmap[cint32_t,double]]& cdef cmap[_module_cbindings.cAnEnumRenamed,cint32_t] Map__AnEnumRenamed_i32__make_instance(object items) except *: cdef cmap[_module_cbindings.cAnEnumRenamed,cint32_t] c_inst + cdef _module_cbindings.cAnEnumRenamed c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, AnEnumRenamed): raise TypeError(f"{key!r} is not of type AnEnumRenamed") + c_key = <_module_cbindings.cAnEnumRenamed>key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[<_module_cbindings.cAnEnumRenamed>key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__AnEnumRenamed_i32__from_cpp(const cmap[_module_cbindings.cAnEnumRenamed,cint32_t]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/py3/out/py3_auto_migrate_legacy_container_converters/gen-py3/module/converter.pyx b/thrift/compiler/test/fixtures/py3/out/py3_auto_migrate_legacy_container_converters/gen-py3/module/converter.pyx index 286814321e1..13197e66191 100644 --- a/thrift/compiler/test/fixtures/py3/out/py3_auto_migrate_legacy_container_converters/gen-py3/module/converter.pyx +++ b/thrift/compiler/test/fixtures/py3/out/py3_auto_migrate_legacy_container_converters/gen-py3/module/converter.pyx @@ -122,17 +122,19 @@ cdef vector[_module_cbindings.cSimpleStruct] List__SimpleStruct__make_instance(o cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -140,47 +142,54 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef cmap[string,string] Map__string_string__make_instance(object items) except *: cdef cmap[string,string] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key.encode('UTF-8')] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef cmap[string,_module_cbindings.cSimpleStruct] Map__string_SimpleStruct__make_instance(object items) except *: cdef cmap[string,_module_cbindings.cSimpleStruct] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, _module_types.SimpleStruct): raise TypeError(f"{item!r} is not of type _module_types.SimpleStruct") - c_inst[key.encode('UTF-8')] = python_to_cpp[_module_cbindings.cSimpleStruct](item) + c_inst[c_key] = python_to_cpp[_module_cbindings.cSimpleStruct](item) return cmove(c_inst) cdef cmap[string,cint16_t] Map__string_i16__make_instance(object items) except *: cdef cmap[string,cint16_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef vector[vector[cint32_t]] List__List__i32__make_instance(object items) except *: @@ -197,31 +206,35 @@ cdef vector[vector[cint32_t]] List__List__i32__make_instance(object items) excep cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef cmap[string,cmap[string,cint32_t]] Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, int]") if not isinstance(item, _module_types.Map__string_i32): item = _module_types.Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_i32__make_instance(item) return cmove(c_inst) cdef vector[cset[string]] List__Set__string__make_instance(object items) except *: @@ -238,17 +251,19 @@ cdef vector[cset[string]] List__Set__string__make_instance(object items) except cdef cmap[string,vector[_module_cbindings.cSimpleStruct]] Map__string_List__SimpleStruct__make_instance(object items) except *: cdef cmap[string,vector[_module_cbindings.cSimpleStruct]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Sequence[_module_types.SimpleStruct]") if not isinstance(item, _module_types.List__SimpleStruct): item = _module_types.List__SimpleStruct(item) - c_inst[key.encode('UTF-8')] = List__SimpleStruct__make_instance(item) + c_inst[c_key] = List__SimpleStruct__make_instance(item) return cmove(c_inst) cdef vector[vector[string]] List__List__string__make_instance(object items) except *: @@ -301,6 +316,7 @@ cdef vector[string] List__binary__make_instance(object items) except *: cdef cset[string] Set__binary__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -308,7 +324,8 @@ cdef cset[string] Set__binary__make_instance(object items) except *: for item in items: if not isinstance(item, bytes): raise TypeError(f"{item!r} is not of type bytes") - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef vector[_module_cbindings.cAnEnum] List__AnEnum__make_instance(object items) except *: @@ -323,17 +340,18 @@ cdef vector[_module_cbindings.cAnEnum] List__AnEnum__make_instance(object items) cdef _module_cbindings._std_unordered_map[cint32_t,cint32_t] _std_unordered_map__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._std_unordered_map[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef _module_cbindings._MyType _MyType__List__i32__make_instance(object items) except *: @@ -349,28 +367,30 @@ cdef _module_cbindings._MyType _MyType__List__i32__make_instance(object items) e cdef _module_cbindings._MyType _MyType__Set__i32__make_instance(object items) except *: cdef _module_cbindings._MyType c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef _module_cbindings._MyType _MyType__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._MyType c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef _module_cbindings._py3_simple_AdaptedList _py3_simple_AdaptedList__List__i32__make_instance(object items) except *: @@ -386,42 +406,45 @@ cdef _module_cbindings._py3_simple_AdaptedList _py3_simple_AdaptedList__List__i3 cdef _module_cbindings._py3_simple_AdaptedSet _py3_simple_AdaptedSet__Set__i32__make_instance(object items) except *: cdef _module_cbindings._py3_simple_AdaptedSet c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef _module_cbindings._py3_simple_AdaptedMap _py3_simple_AdaptedMap__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._py3_simple_AdaptedMap c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef cmap[cint32_t,double] Map__i32_double__make_instance(object items) except *: cdef cmap[cint32_t,double] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, (float, int)): raise TypeError(f"{item!r} is not of type float") - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef vector[cmap[cint32_t,double]] List__Map__i32_double__make_instance(object items) except *: @@ -438,15 +461,17 @@ cdef vector[cmap[cint32_t,double]] List__Map__i32_double__make_instance(object i cdef cmap[_module_cbindings.cAnEnumRenamed,cint32_t] Map__AnEnumRenamed_i32__make_instance(object items) except *: cdef cmap[_module_cbindings.cAnEnumRenamed,cint32_t] c_inst + cdef _module_cbindings.cAnEnumRenamed c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, _module_types.AnEnumRenamed): raise TypeError(f"{key!r} is not of type _module_types.AnEnumRenamed") + c_key = <_module_cbindings.cAnEnumRenamed>key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[<_module_cbindings.cAnEnumRenamed>key] = item + c_inst[c_key] = item return cmove(c_inst) diff --git a/thrift/compiler/test/fixtures/py3/out/py3_legacy_container_converters/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/py3/out/py3_legacy_container_converters/gen-py3/module/types.pyx index c96f7762fbc..bb0c7b55ce2 100644 --- a/thrift/compiler/test/fixtures/py3/out/py3_legacy_container_converters/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/py3/out/py3_legacy_container_converters/gen-py3/module/types.pyx @@ -1713,13 +1713,14 @@ cdef object List__SimpleStruct__from_cpp(const vector[_module_cbindings.cSimpleS cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -1733,6 +1734,7 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -1740,7 +1742,8 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__string__from_cpp(const cset[string]& c_set) except *: @@ -1754,15 +1757,17 @@ cdef object Set__string__from_cpp(const cset[string]& c_set) except *: cdef cmap[string,string] Map__string_string__make_instance(object items) except *: cdef cmap[string,string] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key.encode('UTF-8')] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__string_string__from_cpp(const cmap[string,string]& c_map) except *: @@ -1777,15 +1782,17 @@ cdef object Map__string_string__from_cpp(const cmap[string,string]& c_map) excep cdef cmap[string,_module_cbindings.cSimpleStruct] Map__string_SimpleStruct__make_instance(object items) except *: cdef cmap[string,_module_cbindings.cSimpleStruct] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, SimpleStruct): raise TypeError(f"{item!r} is not of type SimpleStruct") - c_inst[key.encode('UTF-8')] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst[c_key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) return cmove(c_inst) cdef object Map__string_SimpleStruct__from_cpp(const cmap[string,_module_cbindings.cSimpleStruct]& c_map) except *: @@ -1800,16 +1807,18 @@ cdef object Map__string_SimpleStruct__from_cpp(const cmap[string,_module_cbindin cdef cmap[string,cint16_t] Map__string_i16__make_instance(object items) except *: cdef cmap[string,cint16_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i16__from_cpp(const cmap[string,cint16_t]& c_map) except *: @@ -1843,16 +1852,18 @@ cdef object List__List__i32__from_cpp(const vector[vector[cint32_t]]& c_vec) exc cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except *: @@ -1867,17 +1878,19 @@ cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except cdef cmap[string,cmap[string,cint32_t]] Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, int]") if not isinstance(item, Map__string_i32): item = Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_i32__make_instance(item) return cmove(c_inst) cdef object Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string,cint32_t]]& c_map) except *: @@ -1911,17 +1924,19 @@ cdef object List__Set__string__from_cpp(const vector[cset[string]]& c_vec) excep cdef cmap[string,vector[_module_cbindings.cSimpleStruct]] Map__string_List__SimpleStruct__make_instance(object items) except *: cdef cmap[string,vector[_module_cbindings.cSimpleStruct]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Sequence[SimpleStruct]") if not isinstance(item, List__SimpleStruct): item = List__SimpleStruct(item) - c_inst[key.encode('UTF-8')] = List__SimpleStruct__make_instance(item) + c_inst[c_key] = List__SimpleStruct__make_instance(item) return cmove(c_inst) cdef object Map__string_List__SimpleStruct__from_cpp(const cmap[string,vector[_module_cbindings.cSimpleStruct]]& c_map) except *: @@ -2012,6 +2027,7 @@ cdef object List__binary__from_cpp(const vector[string]& c_vec) except *: cdef cset[string] Set__binary__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -2019,7 +2035,8 @@ cdef cset[string] Set__binary__make_instance(object items) except *: for item in items: if not isinstance(item, bytes): raise TypeError(f"{item!r} is not of type bytes") - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__binary__from_cpp(const cset[string]& c_set) except *: @@ -2050,17 +2067,18 @@ cdef object List__AnEnum__from_cpp(const vector[_module_cbindings.cAnEnum]& c_ve cdef _module_cbindings._std_unordered_map[cint32_t,cint32_t] _std_unordered_map__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._std_unordered_map[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object _std_unordered_map__Map__i32_i32__from_cpp(const _module_cbindings._std_unordered_map[cint32_t,cint32_t]& c_map) except *: @@ -2093,13 +2111,14 @@ cdef object _MyType__List__i32__from_cpp(const _module_cbindings._MyType& c_vec) cdef _module_cbindings._MyType _MyType__Set__i32__make_instance(object items) except *: cdef _module_cbindings._MyType c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object _MyType__Set__i32__from_cpp(const _module_cbindings._MyType& c_set) except *: @@ -2113,17 +2132,18 @@ cdef object _MyType__Set__i32__from_cpp(const _module_cbindings._MyType& c_set) cdef _module_cbindings._MyType _MyType__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._MyType c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object _MyType__Map__i32_i32__from_cpp(const _module_cbindings._MyType& c_map) except *: @@ -2156,13 +2176,14 @@ cdef object _py3_simple_AdaptedList__List__i32__from_cpp(const _module_cbindings cdef _module_cbindings._py3_simple_AdaptedSet _py3_simple_AdaptedSet__Set__i32__make_instance(object items) except *: cdef _module_cbindings._py3_simple_AdaptedSet c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object _py3_simple_AdaptedSet__Set__i32__from_cpp(const _module_cbindings._py3_simple_AdaptedSet& c_set) except *: @@ -2176,17 +2197,18 @@ cdef object _py3_simple_AdaptedSet__Set__i32__from_cpp(const _module_cbindings._ cdef _module_cbindings._py3_simple_AdaptedMap _py3_simple_AdaptedMap__Map__i32_i32__make_instance(object items) except *: cdef _module_cbindings._py3_simple_AdaptedMap c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object _py3_simple_AdaptedMap__Map__i32_i32__from_cpp(const _module_cbindings._py3_simple_AdaptedMap& c_map) except *: @@ -2201,16 +2223,17 @@ cdef object _py3_simple_AdaptedMap__Map__i32_i32__from_cpp(const _module_cbindin cdef cmap[cint32_t,double] Map__i32_double__make_instance(object items) except *: cdef cmap[cint32_t,double] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, (float, int)): raise TypeError(f"{item!r} is not of type float") - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_double__from_cpp(const cmap[cint32_t,double]& c_map) except *: @@ -2244,16 +2267,18 @@ cdef object List__Map__i32_double__from_cpp(const vector[cmap[cint32_t,double]]& cdef cmap[_module_cbindings.cAnEnumRenamed,cint32_t] Map__AnEnumRenamed_i32__make_instance(object items) except *: cdef cmap[_module_cbindings.cAnEnumRenamed,cint32_t] c_inst + cdef _module_cbindings.cAnEnumRenamed c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, AnEnumRenamed): raise TypeError(f"{key!r} is not of type AnEnumRenamed") + c_key = <_module_cbindings.cAnEnumRenamed>key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[<_module_cbindings.cAnEnumRenamed>key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__AnEnumRenamed_i32__from_cpp(const cmap[_module_cbindings.cAnEnumRenamed,cint32_t]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx index ae22136b467..700686734ce 100644 --- a/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/refs/out/py3/gen-py3/module/types.pyx @@ -2948,13 +2948,14 @@ cdef object List__i32__from_cpp(const vector[cint32_t]& c_vec) except *: cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -2968,17 +2969,18 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cmap[cint32_t,cint32_t] Map__i32_i32__make_instance(object items) except *: cdef cmap[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_i32__from_cpp(const cmap[cint32_t,cint32_t]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/templated-deserialize/out/py3/gen-py3/module/types.pyx b/thrift/compiler/test/fixtures/templated-deserialize/out/py3/gen-py3/module/types.pyx index 975a9e0c23e..67958f6f637 100644 --- a/thrift/compiler/test/fixtures/templated-deserialize/out/py3/gen-py3/module/types.pyx +++ b/thrift/compiler/test/fixtures/templated-deserialize/out/py3/gen-py3/module/types.pyx @@ -536,15 +536,17 @@ cdef class containerStruct(thrift.py3.types.Struct): cdef cmap[string,cbool] Map__string_bool__make_instance(object items) except *: cdef cmap[string,cbool] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, bool): raise TypeError(f"{item!r} is not of type bool") - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_bool__from_cpp(const cmap[string,cbool]& c_map) except *: @@ -559,13 +561,14 @@ cdef object Map__string_bool__from_cpp(const cmap[string,cbool]& c_map) except * cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -635,16 +638,18 @@ cdef object List__List__List__i32__from_cpp(const vector[vector[vector[cint32_t] cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except *: @@ -659,17 +664,19 @@ cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except cdef cmap[string,cmap[string,cint32_t]] Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, int]") if not isinstance(item, Map__string_i32): item = Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_i32__make_instance(item) return cmove(c_inst) cdef object Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string,cint32_t]]& c_map) except *: @@ -684,17 +691,19 @@ cdef object Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string, cdef cmap[string,cmap[string,cmap[string,cint32_t]]] Map__string_Map__string_Map__string_i32__make_instance(object items) except *: cdef cmap[string,cmap[string,cmap[string,cint32_t]]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Mapping[str, _typing.Mapping[str, int]]") if not isinstance(item, Map__string_Map__string_i32): item = Map__string_Map__string_i32(item) - c_inst[key.encode('UTF-8')] = Map__string_Map__string_i32__make_instance(item) + c_inst[c_key] = Map__string_Map__string_i32__make_instance(item) return cmove(c_inst) cdef object Map__string_Map__string_Map__string_i32__from_cpp(const cmap[string,cmap[string,cmap[string,cint32_t]]]& c_map) except *: @@ -728,17 +737,19 @@ cdef object List__Set__i32__from_cpp(const vector[cset[cint32_t]]& c_vec) except cdef cmap[string,vector[cint32_t]] Map__string_List__i32__make_instance(object items) except *: cdef cmap[string,vector[cint32_t]] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if item is None: raise TypeError("None is not of type _typing.Sequence[int]") if not isinstance(item, List__i32): item = List__i32(item) - c_inst[key.encode('UTF-8')] = List__i32__make_instance(item) + c_inst[c_key] = List__i32__make_instance(item) return cmove(c_inst) cdef object Map__string_List__i32__from_cpp(const cmap[string,vector[cint32_t]]& c_map) except *: @@ -772,12 +783,14 @@ cdef object List__List__List__List__i32__from_cpp(const vector[vector[vector[vec cdef cset[cbool] Set__bool__make_instance(object items) except *: cdef cset[cbool] c_inst + cdef cbool c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, bool): raise TypeError(f"{item!r} is not of type bool") - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__bool__from_cpp(const cset[cbool]& c_set) except *: @@ -791,6 +804,7 @@ cdef object Set__bool__from_cpp(const cset[cbool]& c_set) except *: cdef cset[cset[cbool]] Set__Set__bool__make_instance(object items) except *: cdef cset[cset[cbool]] c_inst + cdef cset[cbool] c_item if items is None: return cmove(c_inst) for item in items: @@ -798,7 +812,8 @@ cdef cset[cset[cbool]] Set__Set__bool__make_instance(object items) except *: raise TypeError("None is not of type _typing.AbstractSet[bool]") if not isinstance(item, Set__bool): item = Set__bool(item) - c_inst.insert(Set__bool__make_instance(item)) + c_item = Set__bool__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__Set__bool__from_cpp(const cset[cset[cbool]]& c_set) except *: @@ -812,6 +827,7 @@ cdef object Set__Set__bool__from_cpp(const cset[cset[cbool]]& c_set) except *: cdef cset[cset[cset[cbool]]] Set__Set__Set__bool__make_instance(object items) except *: cdef cset[cset[cset[cbool]]] c_inst + cdef cset[cset[cbool]] c_item if items is None: return cmove(c_inst) for item in items: @@ -819,7 +835,8 @@ cdef cset[cset[cset[cbool]]] Set__Set__Set__bool__make_instance(object items) ex raise TypeError("None is not of type _typing.AbstractSet[_typing.AbstractSet[bool]]") if not isinstance(item, Set__Set__bool): item = Set__Set__bool(item) - c_inst.insert(Set__Set__bool__make_instance(item)) + c_item = Set__Set__bool__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__Set__Set__bool__from_cpp(const cset[cset[cset[cbool]]]& c_set) except *: @@ -833,6 +850,7 @@ cdef object Set__Set__Set__bool__from_cpp(const cset[cset[cset[cbool]]]& c_set) cdef cset[vector[cint32_t]] Set__List__i32__make_instance(object items) except *: cdef cset[vector[cint32_t]] c_inst + cdef vector[cint32_t] c_item if items is None: return cmove(c_inst) for item in items: @@ -840,7 +858,8 @@ cdef cset[vector[cint32_t]] Set__List__i32__make_instance(object items) except * raise TypeError("None is not of type _typing.Sequence[int]") if not isinstance(item, List__i32): item = List__i32(item) - c_inst.insert(List__i32__make_instance(item)) + c_item = List__i32__make_instance(item) + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__List__i32__from_cpp(const cset[vector[cint32_t]]& c_set) except *: @@ -854,6 +873,7 @@ cdef object Set__List__i32__from_cpp(const cset[vector[cint32_t]]& c_set) except cdef cset[string] Set__string__make_instance(object items) except *: cdef cset[string] c_inst + cdef string c_item if items is None: return cmove(c_inst) if isinstance(items, str): @@ -861,7 +881,8 @@ cdef cset[string] Set__string__make_instance(object items) except *: for item in items: if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst.insert(item.encode('UTF-8')) + c_item = item.encode('UTF-8') + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__string__from_cpp(const cset[string]& c_set) except *: @@ -894,6 +915,7 @@ cdef object List__Set__string__from_cpp(const vector[cset[string]]& c_vec) excep cdef cmap[vector[cset[string]],string] Map__List__Set__string_string__make_instance(object items) except *: cdef cmap[vector[cset[string]],string] c_inst + cdef vector[cset[string]] c_key if items is None: return cmove(c_inst) for key, item in items.items(): @@ -901,10 +923,11 @@ cdef cmap[vector[cset[string]],string] Map__List__Set__string_string__make_insta raise TypeError("None is not of type _typing.Sequence[_typing.AbstractSet[str]]") if not isinstance(key, List__Set__string): key = List__Set__string(key) + c_key = List__Set__string__make_instance(key) if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[List__Set__string__make_instance(key)] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__List__Set__string_string__from_cpp(const cmap[vector[cset[string]],string]& c_map) except *: @@ -919,6 +942,7 @@ cdef object Map__List__Set__string_string__from_cpp(const cmap[vector[cset[strin cdef cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]] Map__Set__List__i32_Map__List__Set__string_string__make_instance(object items) except *: cdef cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]] c_inst + cdef cset[vector[cint32_t]] c_key if items is None: return cmove(c_inst) for key, item in items.items(): @@ -926,12 +950,13 @@ cdef cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]] Map__Set__Li raise TypeError("None is not of type _typing.AbstractSet[_typing.Sequence[int]]") if not isinstance(key, Set__List__i32): key = Set__List__i32(key) + c_key = Set__List__i32__make_instance(key) if item is None: raise TypeError("None is not of type _typing.Mapping[_typing.Sequence[_typing.AbstractSet[str]], str]") if not isinstance(item, Map__List__Set__string_string): item = Map__List__Set__string_string(item) - c_inst[Set__List__i32__make_instance(key)] = Map__List__Set__string_string__make_instance(item) + c_inst[c_key] = Map__List__Set__string_string__make_instance(item) return cmove(c_inst) cdef object Map__Set__List__i32_Map__List__Set__string_string__from_cpp(const cmap[cset[vector[cint32_t]],cmap[vector[cset[string]],string]]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/included/types.pyx b/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/included/types.pyx index 29a620f42fd..438da84fe49 100644 --- a/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/included/types.pyx +++ b/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/included/types.pyx @@ -66,16 +66,17 @@ cdef object get_types_reflection(): cdef _apache_thrift_fixtures_types_included_cbindings.std_unordered_map[cint32_t,string] std_unordered_map__Map__i32_string__make_instance(object items) except *: cdef _apache_thrift_fixtures_types_included_cbindings.std_unordered_map[cint32_t,string] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object std_unordered_map__Map__i32_string__from_cpp(const _apache_thrift_fixtures_types_included_cbindings.std_unordered_map[cint32_t,string]& c_map) except *: diff --git a/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx b/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx index 1f734cc506f..a2a038b8a77 100644 --- a/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx +++ b/thrift/compiler/test/fixtures/types/out/py3/gen-py3/apache/thrift/fixtures/types/module/types.pyx @@ -4137,16 +4137,17 @@ cdef class StructWithDoubleUnderscores(thrift.py3.types.Struct): cdef _apache_thrift_fixtures_types_module_cbindings.std_unordered_map[cint32_t,string] std_unordered_map__Map__i32_string__make_instance(object items) except *: cdef _apache_thrift_fixtures_types_module_cbindings.std_unordered_map[cint32_t,string] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object std_unordered_map__Map__i32_string__from_cpp(const _apache_thrift_fixtures_types_module_cbindings.std_unordered_map[cint32_t,string]& c_map) except *: @@ -4179,16 +4180,18 @@ cdef object List__i64__from_cpp(const vector[cint64_t]& c_vec) except *: cdef cmap[string,cint64_t] Map__binary_i64__make_instance(object items) except *: cdef cmap[string,cint64_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, bytes): raise TypeError(f"{key!r} is not of type bytes") + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__binary_i64__from_cpp(const cmap[string,cint64_t]& c_map) except *: @@ -4293,13 +4296,14 @@ cdef object folly_small_vector__List__i32__from_cpp(const _apache_thrift_fixture cdef _apache_thrift_fixtures_types_module_cbindings.folly_sorted_vector_set[cint32_t] folly_sorted_vector_set__Set__i32__make_instance(object items) except *: cdef _apache_thrift_fixtures_types_module_cbindings.folly_sorted_vector_set[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object folly_sorted_vector_set__Set__i32__from_cpp(const _apache_thrift_fixtures_types_module_cbindings.folly_sorted_vector_set[cint32_t]& c_set) except *: @@ -4313,16 +4317,17 @@ cdef object folly_sorted_vector_set__Set__i32__from_cpp(const _apache_thrift_fix cdef cmap[cint32_t,string] Map__i32_string__make_instance(object items) except *: cdef cmap[cint32_t,string] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, str): raise TypeError(f"{item!r} is not of type str") - c_inst[key] = item.encode('UTF-8') + c_inst[c_key] = item.encode('UTF-8') return cmove(c_inst) cdef object Map__i32_string__from_cpp(const cmap[cint32_t,string]& c_map) except *: @@ -4355,16 +4360,18 @@ cdef object std_list_int32_t__List__i32__from_cpp(const _apache_thrift_fixtures_ cdef cmap[string,cint32_t] Map__string_i32__make_instance(object items) except *: cdef cmap[string,cint32_t] c_inst + cdef string c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, str): raise TypeError(f"{key!r} is not of type str") + c_key = key.encode('UTF-8') if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key.encode('UTF-8')] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__string_i32__from_cpp(const cmap[string,cint32_t]& c_map) except *: @@ -4398,16 +4405,17 @@ cdef object List__std_unordered_map__Map__i32_string__from_cpp(const vector[_apa cdef cmap[cint32_t,_apache_thrift_fixtures_types_module_cbindings.cIncompleteMapDep] Map__i32_IncompleteMapDep__make_instance(object items) except *: cdef cmap[cint32_t,_apache_thrift_fixtures_types_module_cbindings.cIncompleteMapDep] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, IncompleteMapDep): raise TypeError(f"{item!r} is not of type IncompleteMapDep") - c_inst[key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst[c_key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) return cmove(c_inst) cdef object Map__i32_IncompleteMapDep__from_cpp(const cmap[cint32_t,_apache_thrift_fixtures_types_module_cbindings.cIncompleteMapDep]& c_map) except *: @@ -4422,16 +4430,17 @@ cdef object Map__i32_IncompleteMapDep__from_cpp(const cmap[cint32_t,_apache_thri cdef _apache_thrift_fixtures_types_module_cbindings.std_unordered_map[cint32_t,_apache_thrift_fixtures_types_module_cbindings.cCompleteMapDep] std_unordered_map__Map__i32_CompleteMapDep__make_instance(object items) except *: cdef _apache_thrift_fixtures_types_module_cbindings.std_unordered_map[cint32_t,_apache_thrift_fixtures_types_module_cbindings.cCompleteMapDep] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, CompleteMapDep): raise TypeError(f"{item!r} is not of type CompleteMapDep") - c_inst[key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) + c_inst[c_key] = deref((item)._cpp_obj_FBTHRIFT_ONLY_DO_NOT_USE) return cmove(c_inst) cdef object std_unordered_map__Map__i32_CompleteMapDep__from_cpp(const _apache_thrift_fixtures_types_module_cbindings.std_unordered_map[cint32_t,_apache_thrift_fixtures_types_module_cbindings.cCompleteMapDep]& c_map) except *: @@ -4514,13 +4523,14 @@ cdef object List__DependentAdaptedListDep__from_cpp(const vector[_apache_thrift_ cdef cset[cint32_t] Set__i32__make_instance(object items) except *: cdef cset[cint32_t] c_inst + cdef cint32_t c_item if items is None: return cmove(c_inst) for item in items: if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") - item = item - c_inst.insert(item) + c_item = item + c_inst.insert(c_item) return cmove(c_inst) cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: @@ -4534,17 +4544,18 @@ cdef object Set__i32__from_cpp(const cset[cint32_t]& c_set) except *: cdef cmap[cint32_t,cint32_t] Map__i32_i32__make_instance(object items) except *: cdef cmap[cint32_t,cint32_t] c_inst + cdef cint32_t c_key if items is None: return cmove(c_inst) for key, item in items.items(): if not isinstance(key, int): raise TypeError(f"{key!r} is not of type int") - key = key + c_key = key if not isinstance(item, int): raise TypeError(f"{item!r} is not of type int") item = item - c_inst[key] = item + c_inst[c_key] = item return cmove(c_inst) cdef object Map__i32_i32__from_cpp(const cmap[cint32_t,cint32_t]& c_map) except *: