You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by GitBox <gi...@apache.org> on 2022/11/29 19:00:30 UTC

[GitHub] [thrift] Jens-G commented on a diff in pull request #2523: THRIFT-5139: THRIFT-4181: Python3 type hints

Jens-G commented on code in PR #2523:
URL: https://github.com/apache/thrift/pull/2523#discussion_r1035166965


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -2742,8 +2765,71 @@ string t_py_generator::type_name(t_type* ttype) {
   return ttype->get_name();
 }
 
+string t_py_generator::arg_hint(t_type* type) {
+  if(gen_type_hints_) {
+      return ": " + type_to_py_hint(type);
+  }
+
+  return "";
+}
+
+string t_py_generator::func_hint(t_type* type) {
+  if(gen_type_hints_) {
+      return " -> " + type_to_py_hint(type);
+  }
+
+  return "";
+}
+
+/**
+ * Converts the parse type to a Python type hint
+ */
+string t_py_generator::type_to_py_hint(t_type* type) {
+  return "typing.Optional[" + type_to_py_type(type) + "]";

Review Comment:
   In short, service method arguments are not "optional". They are mandatory, at least that's the current de-facto standard with Thrift. Note that the syntax would allow both optional and default values but hardly any language (if any at all) has any support for it. Hence, given the current state I would vote for the optional here being incorrect.
   
   Note I'm not saying this is the ultimative decision and law until end of times. It's just what is consistent with the rest of Thrift as it exists today. Thios certainly could be changed, but that will be some pile of work for sure.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@thrift.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org