fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1254757164
##########
test/py/TestClient.py:
##########
@@ -256,6 +256,26 @@ def testMultiException(self):
y = self.client.testMultiException('success', 'foobar')
self.assertEqual(y.string_thing, 'foobar')
+ def testException__traceback__(self):
+ print('testException__traceback__')
+ self.client.testException('Safe')
+ try:
+ self.client.testException('Xception')
+ self.fail("should have gotten exception")
+ except Xception as x:
+ uses_slots = hasattr(x, '__slots__')
+ try:
+ x.__traceback__ = x.__traceback__
+ self.assertTrue(
+ uses_slots,
+ 'expected editable exception to use slots, no slots
defined',
+ )
+ except Exception as e:
+ self.assertTrue(
+ isinstance(e, TypeError),
Review Comment:
this should be `isinstance(e, TypeError) and not uses_slots` instead?
##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -888,12 +888,30 @@ 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, *args):" << endl;
+ indent_up();
+ if (gen_slots_) {
Review Comment:
please add some comments inside this `if` block, with link to the jira
ticket, to explain why we have this check.
##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -888,12 +888,30 @@ 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, *args):" << endl;
+ indent_up();
+ if (gen_slots_) {
+ out << indent() << "if args[0] not in self.__slots__:" << endl;
+ indent_up();
+ out << indent() << "super().__setattr__(*args)" << endl
+ << indent() << "return" << endl;
+ indent_down();
+ }
+ out << indent() << "raise TypeError(\"can't modify immutable instance\")"
<< endl;
+ indent_down();
+ out << endl;
+ out << indent() << "def __delattr__(self, *args):" << endl;
+ indent_up();
+ if (gen_slots_) {
Review Comment:
same here
--
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]