You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@aurora.apache.org by GitBox <gi...@apache.org> on 2019/09/15 20:02:52 UTC

[GitHub] [aurora] StephanErb commented on issue #68: Python 2 sunsetting in Jan 2020

StephanErb commented on issue #68: Python 2 sunsetting in Jan 2020
URL: https://github.com/apache/aurora/issues/68#issuecomment-531594878
 
 
   We have looked into Python 3, a bit as we consume Aurora 's API from within Python.
   
   Code wise there will not be too many hurdles. However there is a bit of pain with Thrift: Aurora's API require `Set`s in many places and this requires Thrift objects to be hashable in Python. Unfortunately Thrifts generated code by default comes without suitable hash methods for Python 3.
   
   We have resorted to this nasty hack for now: 
   ```
   # With python 3 objects need a hash method to put them inside of sets. This was not the
   # case in python 2. We monkeypatch a hash method on to the the thrift objects to make them
   # compatible with python 3 code without having to make any changes to the thrift api
   # itself.
   def __hash__(self):
       return hash(self.__class__) ^ hash(1)
   
   
   setattr(Resource, "__hash__", __hash__)
   setattr(Metadata, "__hash__", __hash__)
   setattr(Constraint, "__hash__", __hash__)
   ```
   
   Thrift have a few options to change how code is generated. This might be something worth exploring. Another potential option could be to migrate to https://pypi.org/project/thriftpy2/ 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services