You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by GitBox <gi...@apache.org> on 2022/09/23 08:36:07 UTC

[GitHub] [thrift] grzegorzlyczba opened a new pull request, #2676: THRIFT-4623: Create new instance of default value for mutable types

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

   Client: py
   
   Default values have a single instance what's fine for non-mutable types, but any change made for list, class, etc are propagated to all instances
   ```
   >>> from gen.test import ttypes
   >>> b1 = ttypes.B()
   >>> b1
   B(itm=A(value=None))
   >>> b1.itm.value = 1
   >>> b2 = ttypes.B()
   >>> b2
   B(itm=A(value=None))
   >>> b1
   B(itm=A(value=1))
   >>>
   ```
   
   With this change, generator will set `None` as default value for such params and add a check in `__init__` method to create new instance when the value is `None`.
   
   ```py
   def __init__(self, itm=None,):
       if itm is None:
           itm = A(**{
           })
       self.itm = itm
   ```
   It works for types defined in the same file, the only limitation is to create recurrence types with a default value of the same type because it generates inf recursion.
   
   Apache Jira ticket: https://issues.apache.org/jira/browse/THRIFT-4623
   
     
   - [x] Did you create an [Apache Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?  (not required for trivial changes)
   - [x] If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
   - [x] Did you squash your changes to a single commit?  (not required, but preferred)
   - [x] Did you do your best to avoid breaking changes?  If one was needed, did you label the Jira ticket with "Breaking-Change"?
   - [x] If your change does not involve any code, include `[skip ci]` anywhere in the commit message to free up build resources.


-- 
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] grzegorzlyczba commented on pull request #2676: THRIFT-4623: Create new instance of default value for mutable types

Posted by GitBox <gi...@apache.org>.
grzegorzlyczba commented on PR #2676:
URL: https://github.com/apache/thrift/pull/2676#issuecomment-1255963021

   I removed the last element in `thrift_spec` tuples with default instance (it was used only in `__init__` to check the param value, but it was always failing). I don't see any other place where it's still in use.


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