1

In a python-based project, I would like to use features data classes and libraries such as the current RxPY version.

However, we are bound to an environment (a Yocto-system) that only has Python 3.5.5

From TypeScript/JavaScript I know that some languages allow code to be transpiled to a lower language version.

Can Python 3.7 code be transpiled to a lower version?

Many thanks

David Brem
  • 504
  • 2
  • 6
  • 16
  • Python isn't compiled at all, so I'm not sure what you're saying. The code might need small adjustments to work with lower versions of python 3. Why not just try it and see where it fails? – Ofer Sadan Nov 21 '19 at 07:24
  • Hello Ofer, thanks for your quick answer. Maybe this is a terminology-related thing and "compiling" is not the right word. I would like to use data classes which have come to python in version 3.7. In JavaScript I would use a tool like Babel that rewrites ("transpiles") my code into the syntax of a lower ECMAScript version. I was hoping that such a tool would exist for Python as well. I will adjust the title of my post to avoid confusion. – David Brem Nov 21 '19 at 07:36

1 Answers1

2

You can't just use a tool to convert Python code to earlier versions, because those versions would sometime lack the libraries that you need. Using Python 3.7's dataclass is a good example.

A workaround for you would be to just install a port of dataclasses back in your 3.5 environment. This would be tricky. If you had python 3.6 you could just install this through

pip install dataclasses

But you can see in this issue that they never ported it back for python 3.5. If you check out their GitHub, maybe there are manual changes you could do to the source code to make it work. Maybe.

The easier way would be to find an alternative to dataclasses

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62