fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1232783566


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -888,12 +888,33 @@ void 
t_py_generator::generate_py_struct_definition(ostream& out,
 
   if (is_immutable(tstruct)) {
     out << endl;
-    out << indent() << "def __setattr__(self, *args):" << endl
-        << indent() << indent_str() << "raise TypeError(\"can't modify 
immutable instance\")" << endl
-        << endl;
-    out << indent() << "def __delattr__(self, *args):" << endl
-        << indent() << indent_str() << "raise TypeError(\"can't modify 
immutable instance\")" << endl
-        << endl;
+    out << indent() << "def __setattr__(self, attr, value):" << endl;
+    indent_up();
+    if (gen_slots_) {
+      out << indent() << "if attr not in self.__slots__:" << endl;
+    } else {
+      out << indent() << "if not self.__dict__.has_key(attr):" << endl;

Review Comment:
   this might not work as expected:
   ```
   $ python3
   Python 3.11.4 (main, Jun  7 2023, 10:13:09) [GCC 12.2.0] on linux
   Type "help", "copyright", "credits" or "license" for more information.
   >>> class Foo:
   ...   _bar = None
   ... 
   >>> foo = Foo()
   >>> foo.__dict__
   {}
   >>> foo._bar = 1
   >>> foo.__dict__
   {'_bar': 1}
   ```
   it seems that the `__dict__` would only have the key if it's used at least 
once?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to