This is an automated email from the ASF dual-hosted git repository.
yuxuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new b2c5805b4 Fix typename for value in map for python gen code
b2c5805b4 is described below
commit b2c5805b40645ab9713d895535d37296b91fc1ef
Author: Roshan Rajan <[email protected]>
AuthorDate: Mon Jun 26 18:03:03 2023 -0700
Fix typename for value in map for python gen code
---
compiler/cpp/src/thrift/generate/t_py_generator.cc | 2 +-
test/py/explicit_module/runtest.sh | 3 ++
test/py/explicit_module/shared_types.thrift | 26 ++++++++++++++++++
test/py/explicit_module/test4.thrift | 32 ++++++++++++++++++++++
4 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/compiler/cpp/src/thrift/generate/t_py_generator.cc
b/compiler/cpp/src/thrift/generate/t_py_generator.cc
index 857cb77fd..7063ab21e 100644
--- a/compiler/cpp/src/thrift/generate/t_py_generator.cc
+++ b/compiler/cpp/src/thrift/generate/t_py_generator.cc
@@ -607,7 +607,7 @@ string t_py_generator::render_const_value(t_type* type,
t_const_value* value) {
int64_t int_val = value->get_integer();
if (gen_enum_) {
t_enum_value* enum_val = ((t_enum*)type)->get_constant_by_value(int_val);
- out << type->get_name() << "." << enum_val->get_name();
+ out << type_name(type) << "." << enum_val->get_name();
} else {
out << int_val;
}
diff --git a/test/py/explicit_module/runtest.sh
b/test/py/explicit_module/runtest.sh
index 6d7346283..244505029 100755
--- a/test/py/explicit_module/runtest.sh
+++ b/test/py/explicit_module/runtest.sh
@@ -23,9 +23,12 @@ rm -rf gen-py
../../../compiler/cpp/thrift --gen py test1.thrift || exit 1
../../../compiler/cpp/thrift --gen py test2.thrift || exit 1
../../../compiler/cpp/thrift --gen py test3.thrift && exit 1 # Fail since
test3.thrift has python keywords
+../../../compiler/cpp/thrift --gen py:enum shared_types.thrift || exit 1
+../../../compiler/cpp/thrift --gen py:enum test4.thrift || exit 1
PYTHONPATH=./gen-py python -c 'import foo.bar.baz' || exit 1
PYTHONPATH=./gen-py python -c 'import test2' || exit 1
PYTHONPATH=./gen-py python -c 'import test1' &>/dev/null && exit 1 # Should
fail.
+PYTHONPATH=./gen-py python -c 'import test4.constants' || exit 1
cp -r gen-py simple
../../../compiler/cpp/thrift -r --gen py test2.thrift || exit 1
PYTHONPATH=./gen-py python -c 'import test2' || exit 1
diff --git a/test/py/explicit_module/shared_types.thrift
b/test/py/explicit_module/shared_types.thrift
new file mode 100644
index 000000000..9150f8e02
--- /dev/null
+++ b/test/py/explicit_module/shared_types.thrift
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace py shared_types
+
+enum SharedEnum {
+ SharedEnum0 = 0,
+ SharedEnum1 = 1
+}
+
diff --git a/test/py/explicit_module/test4.thrift
b/test/py/explicit_module/test4.thrift
new file mode 100644
index 000000000..91e9b36db
--- /dev/null
+++ b/test/py/explicit_module/test4.thrift
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+namespace py test4
+
+include "shared_types.thrift"
+
+enum TestEnum {
+ TestEnum0 = 0,
+ TestEnum1 = 1,
+}
+
+const map<TestEnum, shared_types.SharedEnum> typeConversion = {
+ TestEnum.TestEnum0: shared_types.SharedEnum0,
+ TestEnum.TestEnum1: shared_types.SharedEnum1,
+}
\ No newline at end of file