You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by "salomon-smekecohen (via GitHub)" <gi...@apache.org> on 2024/06/10 21:44:20 UTC

Re: [PR] THRIFT-5139/THRIFT-4181: Python3 type hints [thrift]

salomon-smekecohen commented on code in PR #2929:
URL: https://github.com/apache/thrift/pull/2929#discussion_r1633868059


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -2800,8 +2840,78 @@ 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_type(type);
+  }
+
+  return "";
+}
+
+string t_py_generator::member_hint(t_type* type, t_field::e_req req) {
+  if (gen_type_hints_) {
+    if (req != t_field::T_REQUIRED) {
+      return ": typing.Optional[" + type_to_py_type(type) + "]";

Review Comment:
   Theres really no benefit to `| None` besides style. I love that syntax too but this is quite convenient for making it work "always" and without any need to add branches.



-- 
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