You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "KTAtkinson (via GitHub)" <gi...@apache.org> on 2023/06/12 23:40:30 UTC

[GitHub] [thrift] KTAtkinson opened a new pull request, #2816: THRIFT-5715 Python flag to generate mutible exceptions

KTAtkinson opened a new pull request, #2816:
URL: https://github.com/apache/thrift/pull/2816

   In Python 3.11 exceptions generated by the compiler can't be used with a context manager because they are immutable. As of Python 3.11 `contextlib.contextmanager` sets `exc.__stacktrace__` in the event that the code in the context manager errors.
   
   This change adds a compiler flag for Python that generates all exceptions as mutable so they can be used with a context manager.
   
   <!-- Explain the changes in the pull request below: -->
     
   
   <!-- We recommend you review the checklist/tips before submitting a pull request. -->
   
   - [ ] Did you create an [Apache Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?  ([Request account here](https://selfserve.apache.org/jira-account.html), not required for trivial changes)
   - [ ] If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
   - [ ] Did you squash your changes to a single commit?  (not required, but preferred)
   - [ ] Did you do your best to avoid breaking changes?  If one was needed, did you label the Jira ticket with "Breaking-Change"?
   - [ ] If your change does not involve any code, include `[skip ci]` anywhere in the commit message to free up build resources.
   
   <!--
     The Contributing Guide at:
     https://github.com/apache/thrift/blob/master/CONTRIBUTING.md
     has more details and tips for committing properly.
   -->
   


-- 
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: dev-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] KTAtkinson commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
KTAtkinson commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1238799949


##########
test/py/TestClient.py:
##########
@@ -256,6 +257,19 @@ def testMultiException(self):
         y = self.client.testMultiException('success', 'foobar')
         self.assertEqual(y.string_thing, 'foobar')
 
+    def testExceptionInContextManager(self):

Review Comment:
   I think there should be some sort of test here. I originally wrote the test testing the functionality directly, assigning and deleting particular attributes. I wasn't able to write a test to ensure that user defined attributes are not editable as in some cases they are editable. 
   
   My thinking with this test case is that it will at least catch the specific failure when Thrift is updated to use Python 3.11. I did try to run this test with 3.11 but there are parts of the test script that aren't compatible with 3.11.
   
   Thoughts on how to effectively write at test 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: notifications-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1239085659


##########
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:
   my main concern here is that after contextmanager changes the `__traceback__` it will start to appear in `__dict__` and then it can no longer be changed again



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


[GitHub] [thrift] fishy commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1592093389

   > appvayor is currently failing, but it's also failing on all other PRs. Is this expected?
   
   kind of.
   
   but I think a better fix is to limit the scope of immutability of exceptions. we only need to limit the fields used by `__hash__` and `__eq__` to be immutable, and allow mutations of all other fields.


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


[GitHub] [thrift] KTAtkinson commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
KTAtkinson commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1230260807


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -105,7 +106,9 @@ class t_py_generator : public t_generator {
         }
         if( import_dynbase_.empty()) {
           import_dynbase_ = "from thrift.protocol.TBase import TBase, TFrozenBase, TExceptionBase, TFrozenExceptionBase, TTransport\n";
-        }
+        } 
+      } else if( iter->first.compare("immutable_exc") == 0) {

Review Comment:
   Yea this naming is a bit confusing, I'll update it :)



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


[GitHub] [thrift] KTAtkinson commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
KTAtkinson commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1624091570

   @fishy Have time to take a look at this again?


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


[GitHub] [thrift] KTAtkinson commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] KTAtkinson commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
KTAtkinson commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1246874517


##########
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:
   Long story short, `__traceback__` does not appear in `__dict__` from what I could track down it's because the implementation of `Exception` is in C and `__traceback__` is not technically an official property.
   
   Fishy and I discussed off PR and decided that it was acceptable to only support context managers (in Python 3.11) with when using slots. This means any user that runs into this issue should use slots to get around their issue.



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


[GitHub] [thrift] fishy merged pull request #2816: THRIFT-5715: Python non-user defined fields mutable with slots

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy merged PR #2816:
URL: https://github.com/apache/thrift/pull/2816


-- 
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: dev-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] fishy commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1624113606

   >it was acceptable to only support context managers (in Python 3.11) with when using slots.
   
   also to clarify, I said it's acceptable to limit the scope of this PR to only fix the slots use-case, but that does not fully fix the issue (so we cannot close the issue with this PR merged) and we should still fix the non-slots use-case later.


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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1230246084


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -105,7 +106,9 @@ class t_py_generator : public t_generator {
         }
         if( import_dynbase_.empty()) {
           import_dynbase_ = "from thrift.protocol.TBase import TBase, TFrozenBase, TExceptionBase, TFrozenExceptionBase, TTransport\n";
-        }
+        } 
+      } else if( iter->first.compare("immutable_exc") == 0) {

Review Comment:
   shouldn't this be called `mutable_exc` instead? otherwise you are making `gen_immutable_exc_` to false when user pass in `immutable_exc` arg to the compiler.



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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python non-user defined fields mutable with slots

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1256493495


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -893,12 +893,42 @@ 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();
+
+    // Not user-provided fields should be editable so that the Python Standard L`ibrary can edit

Review Comment:
   ```suggestion
       // Not user-provided fields should be editable so that the Python Standard Library can edit
   ```



##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -893,12 +893,42 @@ 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();
+
+    // Not user-provided fields should be editable so that the Python Standard L`ibrary can edit
+    // internal fields of std library base classes. For example, in Python 3.11 context managers
+    // edit the `__traceback__` field on Exceptions. Allowing this to work with `__slots__` is

Review Comment:
   ```suggestion
       // internal fields of std library base classes. For example, in Python 3.11 ContextManager
       // edits the `__traceback__` field on Exceptions. Allowing this to work with `__slots__` is
   ```



##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -893,12 +893,42 @@ 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();
+
+    // Not user-provided fields should be editable so that the Python Standard L`ibrary can edit
+    // internal fields of std library base classes. For example, in Python 3.11 context managers
+    // edit the `__traceback__` field on Exceptions. Allowing this to work with `__slots__` is
+    // trivial because we know which fields are user-provided, without slots we need to build a
+    // way to know which fields are user-provided.
+    if (gen_slots_ && !gen_dynamic_) {
+        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();
+
+    // Not user-provided fields should be editable so that the Python Standard L`ibrary can edit
+    // internal fields of std library base classes. For example, in Python 3.11 context managers
+    // edit the `__traceback__` field on Exceptions. Allowing this to work with `__slots__` is

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: notifications-unsubscribe@thrift.apache.org

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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1254779642


##########
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:
   or probably better split into 2 separated asserts.



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


[GitHub] [thrift] fishy commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1624129057

   please also rebase your change on top of latest master. there are 2 commits related to py compiler merged recently and I want to make sure that this does not break those changes.


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


[GitHub] [thrift] KTAtkinson commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
KTAtkinson commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1592038017

   appvayor is currently failing, but it's also failing on all other PRs. Is this expected?
   


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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1232775864


##########
test/py/TestClient.py:
##########
@@ -256,6 +257,19 @@ def testMultiException(self):
         y = self.client.testMultiException('success', 'foobar')
         self.assertEqual(y.string_thing, 'foobar')
 
+    def testExceptionInContextManager(self):

Review Comment:
   We don't really run python 3.11 in github actions so this test doesn't really verify that it fixes the issue you are seeing right now, but it will eventually.



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


[GitHub] [thrift] KTAtkinson commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "KTAtkinson (via GitHub)" <gi...@apache.org>.
KTAtkinson commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1595206198

   I updated this so that the generated python only considers fields in the `__dict__` or `__slots__` field when Thrift types are immutable.


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


[GitHub] [thrift] fishy commented on a diff in pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on code in PR #2816:
URL: https://github.com/apache/thrift/pull/2816#discussion_r1230246084


##########
compiler/cpp/src/thrift/generate/t_py_generator.cc:
##########
@@ -105,7 +106,9 @@ class t_py_generator : public t_generator {
         }
         if( import_dynbase_.empty()) {
           import_dynbase_ = "from thrift.protocol.TBase import TBase, TFrozenBase, TExceptionBase, TFrozenExceptionBase, TTransport\n";
-        }
+        } 
+      } else if( iter->first.compare("immutable_exc") == 0) {

Review Comment:
   shouldn't this be called `mutable_exc` or `allow_mutable_exc` instead? otherwise you are making `gen_immutable_exc_` to false when user pass in `immutable_exc` arg to the compiler.



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


[GitHub] [thrift] fishy commented on pull request #2816: THRIFT-5715: Python flag to generate mutable exceptions

Posted by "fishy (via GitHub)" <gi...@apache.org>.
fishy commented on PR #2816:
URL: https://github.com/apache/thrift/pull/2816#issuecomment-1624382714

   Please also change the title of this PR accordingly. You are no longer adding a flag to allow mutable exceptions.


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