KTAtkinson commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1238813473
##########
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:
Currently, it looks like [each use defined
field](https://github.com/apache/thrift/pull/2816/files#diff-ad110290fb2055999f700940287b9f8db58007832084247e6ffb0bd2b14b897dR850-R887)
is explicitly set in the `__init__`. I believe this would avoid this issue. Is
that not correct?
Alternately I could keep track of user defined fields similar to how we do
for `__slots__`, thoughts?
--
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]