Skip to content

py2many test cases #61

@jayvdb

Description

@jayvdb

I am looking for a python to JS implementation to run within or alongside https://github.com/adsharma/py2many , and running pj on the tests in https://github.com/adsharma/py2many/tree/main/tests/cases I found some issues, that I thought worth sharing.

Most obvious is lack of support for __name__, especially if __name__ === "__main__":. This isnt a big problem, as py2many can rewrite this before invoking pj.

Another is that the typing import is not removed, which is already raised at #21 .

Beyond that, compilation to ES6 fails for

  • byte_literals.py: ValueError: Unknown data type received.
  • coverage.py (which is lots of various syntax): ValueError: Unknown data type received.
  • global2.py: TransformationError: Node type 'Set': Line: 10, column: 6. No transformation for the node
  • str_enum.py: UnsupportedSyntaxError: Node type 'ClassDef': Line: 6, column: 0. Multiple inheritance is not supported
  • with_open.py: TransformationError: Node type 'With': Line: 7, column: 4. No transformation for the node

Many others fail for ES5 mode because they are using imports, usually of stdlib, and especially of stdlib which should just be stripped, especially typing c.f. #21 (comment)

Invoking the successfully transpiled JS code often fails. e.g. [].append is not translated into the JS equivalent [].push, which is breaking a few of the tests at runtime. After I manually fix that, a fun one is bitops.py which fails because of bitops on booleans is resulting in ints instead of booleans. i.e. pj causes ands to be [ 0, 0, 0, 1 ] which is not equal to [false, false, false, true]. I've found bitops.py trips all of the Python to JavaScript transpilers that I've tried.

The new Set syntax {1, 2} should be easy to implement assuming that set type is already implemented.

stdlib enum support is covered by cases int_enum and str_enum. These are special cases where multiple inheritance is used (mostly) to inform the underlying Python class about behaviour of the members, and could be roughly supported without actually supporting multiple inheritance. e.g. py2many detects specific multiple base combinations for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions