1. 2
  1.  

  2. 1

    In Python 2.7, generators cannot return a value, so the above code snippet actually isn’t valid Python 2.7. In the first version of Asynq, the last value yielded by an asynchronous function would be interpreted as the return value of the function. However, this meant overloading the meaning of the yield keyword, which made code hard to read. As an alternative solution, we back-ported support for returning a value from a generator—introduced in PEP 380—from Python 3 to Python 2.7, and we’re currently using a patched version of Python 2.7 in our codebase where necessary.

    The pattern I’ve seen for this in Python 2.7 is use raise Return(value) from the generator and use except to catch it. Not as nice as newer versions of Python, but at least it’s not a patched interpreter. It makes you wonder: Why not upgrade to Python 3? How is maintaining a fork of Python 2.7 easier?

    1. 1

      There are still quite some libraries that don’t support Python 3. Especially the libraries around analytics and machine learning are often 2.7 only. Quora uses machine learning extensively. I don’t know but that could be one theory as to why they use python 2.7.

      1. 4

        Do you know which ones they’re dependent on? NumPy, SciPy, scikitlearn, Pandas, Tensorflow all work with Python 3.