Search code examples
python-3.xcompatibilitytranspilerrx-py

Can I transpile python 3.7 code to a lower version?


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


Solution

  • 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