Py-backwards Online Demo

Py-backwards is an open-source Python to Python compiler that allows you to use some Python 3.6 features in older versions. This is an example implementation.

Source code is available on GitHub.

def returning_range(x: int): yield from range(x) return x def x_printer(x): val: int val = yield from returning_range(x) print(f'val {val}') def formatter(x: int) -> dict: items: list = [*x_printer(x), x] print(*items, *items) return {'items': items} result = {'x': 10, **formatter(10)} print(result) class NumberManager: def ten(self): return 10 @classmethod def eleven(cls): return 11 class ImportantNumberManager(NumberManager): def ten(self): return super().ten() @classmethod def eleven(cls): return super().eleven() print(ImportantNumberManager().ten()) print(ImportantNumberManager.eleven())
from __future__ import absolute_import from __future__ import division from __future__ import print_function def _py_backwards_merge_dicts(dicts): result = {} for dict_ in dicts: result.update(dict_) return result def returning_range(x): _py_backwards_iterable_6 = iter(range(x)) while True: try: (yield next(_py_backwards_iterable_6)) except StopIteration as _py_backwards_exc_5: break _py_backwards_exc_9 = StopIteration() _py_backwards_exc_9.value = x raise _py_backwards_exc_9 def x_printer(x): _py_backwards_iterable_8 = iter(returning_range(x)) while True: try: (yield next(_py_backwards_iterable_8)) except StopIteration as _py_backwards_exc_7: if hasattr(_py_backwards_exc_7, 'value'): val = _py_backwards_exc_7.value break print(''.join(['val ', '{}'.format(val)])) def formatter(x): items = (list(x_printer(x)) + [x]) # type: list print(*(list(items) + list(items))) return {'items': items} result = _py_backwards_merge_dicts([{'x': 10}, dict(formatter(10))]) print(result) class NumberManager(object): def ten(self): return 10 @classmethod def eleven(cls): return 11 class ImportantNumberManager(NumberManager): def ten(self): return super(ImportantNumberManager, self).ten() @classmethod def eleven(cls): return super(ImportantNumberManager, cls).eleven() print(ImportantNumberManager().ten()) print(ImportantNumberManager.eleven())