metapensiero / metapensiero.pj Goto Github PK
View Code? Open in Web Editor NEWJavascript for refined palates: a Python 3 to ES6 Javascript translator
License: Other
Javascript for refined palates: a Python 3 to ES6 Javascript translator
License: Other
Readme shows this for if elif else..
if ((foo > 0)) {
....
} else {
if ((foo < 0)) {
....
} else {
....
}
}
Personally i prefer the "else if" style instead:
if {
....
}
else if {
...}
else if {
...
}
else {
..
}
Pyxl is a JSX-like syntax for Python:
image_name = "bolton.png"
image = <img src="/static/images/{image_name}" />
text = "Michael Bolton"
block = <div>{image}{text}</div>
element_list = [image, text]
block2 = <div>{element_list}</div>
It is not official, but was kinda endorsed by GvR who ported it to Python 3 at some point (gvanrossum/pyxl3). It would be much more useful with React though, as a replacement for JSX:
from react import React
...
__default__ = "App"
class App(React.Component):
state = {"isLoadingComplete": False}
def render(self):
if not self.state["isLoadingComplete"] and not self.props["skipLoadingScreen"]:
return <AppLoading
startAsync={self.load_resources_async}
onError={self.handle_loading_error}
onFinish={self.handle_finish_loading}
/>
else:
return <View style={styles.container}>
{<StatusBar barStyle="default" /> if Platform.OS == "ios" else None}
<AppNavigator />
</View>
...
What do you think?
Hello @azazel75
You have done a great work man, really I mean it. This is an awesome project and I liked it so much. 😄
I want to start contributing to this project, are there any particular contributing guidelines, if not what are the highest priorities that need to be solved or added for now, I can help you out with those.
Thanks.
Recently there seems to be a surge of Python to JavaScript transpiler projects.
I had hoped to find a comparison of metapensiero with other transpilers like e.g. Transcrypt or projects with a similar direction like Brython in the readme and some information what makes this project distinct and why I would want to try it.
Input:
N = int.from_bytes
I maintain the python-javascripthon package on Arch Linux (https://aur.archlinux.org/packages/python-javascripthon). If you "release/tag" the version with the changes that remove the macropy dependency, then I could get the package working on Arch again.
This is such a great program. Thank you!
Note:
Automatic conversion of isdigit() would be amazing
I am in the process of creating a Webpack loader for this library, but I am unable to retrieve the source map if I send a string into the CLI. The -s option is capable of receiving a string with new lines, shouldn't it be able to figure out the source map even if there isn't a file?
Also, a quick way to test this is the following:
$ pj --inline-map -s "$(<somefile.py)"
yeyupro:metapensiero yemingyu$ /Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -m pj.main -d -s '"foo" if True else "bar"'
Namespace(debug=True, dump_ast=False, es5=False, es6=True, eval=False, files=[], inline_map=False, output=None, pdb=False, source_name=None, stage3=True, string='"foo" if True else "bar"', truntime=False)
DEBUG:main:Log started
INFO:macropy.core.import_hooks:Expand macros in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/metapensiero/pj/transformations/classes.py
INFO:macropy.core.macros:Finding macros in 'metapensiero.pj.transformations.classes'
INFO:macropy.core.macros:Importing macros from 'macropy.core.quotes' into 'metapensiero.pj.transformations.classes'
INFO:macropy.core.macros:Importing macros from 'macropy.experimental.pattern' into 'metapensiero.pj.transformations.classes'
INFO:macropy.core.import_hooks:Expand macros in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/macropy/experimental/init.py
INFO:macropy.core.macros:Finding macros in 'macropy.experimental'
INFO:macropy.core.import_hooks:Expand macros in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/macropy/experimental/pattern.py
INFO:macropy.core.macros:Finding macros in 'macropy.experimental.pattern'
INFO:macropy.core.macros:Importing macros from 'macropy.core.quotes' into 'macropy.experimental.pattern'
INFO:macropy.core.macros:Importing macros from 'macropy.core.hquotes' into 'macropy.experimental.pattern'
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 266
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 268
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 270
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 273
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 275
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 280
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 287
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 299
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 308
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 310
DEBUG:macropy.core.macros:Found macro 'hq', type 'Block', line 333
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 336
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 342
DEBUG:macropy.core.macros:Found macro 'hq', type 'Expr', line 395
DEBUG:macropy.core.macros:Found macro 'q', type 'Block', line 255
DEBUG:macropy.core.macros:Found macro 'switch', type 'Block', line 393
DEBUG:macropy.core.macros:Found macro 'q', type 'Expr', line 395
DEBUG:macropy.core.macros:Found macro 'q', type 'Expr', line 402
DEBUG:macropy.core.macros:Found macro 'q', type 'Expr', line 405
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/main.py", line 266, in
main()
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/main.py", line 163, in main
res = transform_string(input, es5, es6, stage3,
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/main.py", line 112, in transform_string
res, src_map = api.translates(input, enable_es6=enable_es6,
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/api.py", line 167, in translates
src_map = js_code_block.sourcemap(complete_src or src_text, src_filename,
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/processor/util.py", line 377, in sourcemap
for m in self.src_mappings(src_offset, dst_offset):
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/processor/util.py", line 363, in src_mappings
for m in line.src_mappings():
File "/Users/yemingyu/TranslatorUtil/metapensiero.pj/src/metapensiero/pj/processor/util.py", line 264, in src_mappings
assert isinstance(self.item, Part)
AssertionError
After successfully installing javascripthon-0.2 in a virtualenv, attempting the following:
python -m metapensiero.pj -5 pending.py
gets the following error:
An error occurred while compiling source file 'pending.py'
FileNotFoundError: [Errno 2] No such file or directory: ' /lib/python3.5/site-packages/metapensiero/pj/data/babel-6.4.4.min.js'
The entire metapensiero/pj/data directory is missing from the installed package.
Python supports operator overriding, js does not. Perhaps there is a way to achieve this using some means. Documentation comes to mind, maybe comments, what else could potentially be used?
The following code results in an error:
UnsupportedSyntaxError: Node type 'For': ... . Target must be a name, Are you sure is only one?
some_dict = dict()
for key, value in some_dict.items():
# ...
Transcrypt for example is translating this to:
for (var [key, value] of some_dict.py_items()) {
// ...
}
An alternative would perhaps be:
Object.keys(some_dict).forEach(key => {
const value = some_dict[key];
// ...
}
While compiling files in https://github.com/retorquere/biblib, I'm getting
An error occurred while compiling source file 'test.py'
NameError: name 'hq' is not defined
Compiling on the client side would be nice.
My use case is building an IDE.
I'm also looking at:
beeware/batavia#294
Currently it seems I'm limited to Rapydscript, Skulpt or Brython.
Comments welcome.
Thanks!
Self-reference does not need to be named self but can have any name, that's why We write it there. If it was always self there would be no point to write it there.
Since this repository is just a mirror of the GitLab one, and the readme suggests that bug reports and merge requests should be submitted via GitLab, not GitHub, it begs the question why this repository even exists? And why the issue tracker functionality has not been disabled.
Trying to use django-enumfields with this project (https://github.com/hzdg/django-enumfields). The syntax to override a field label is a nested class. Example enum:
import enumfields
class Test(enumfields.IntEnum):
FIRST = 1
SECOND = 2
class Labels:
FIRST = 'fIrSt'
The error is something like
UnsupportedSyntaxError: Node type 'ClassDef': Line: 4, column: 0. Class' body members must be functions or assignments
Torn between trying to make the syntax less crazy on the enumfields, vs some kind of super super limited nested class support. This is pure syntatic sugar, and not necessary.. expect for it is how this code runs. If you look at what labels is actually doing, it's not much.. ( https://github.com/hzdg/django-enumfields/blob/master/enumfields/enums.py)
Input:
a = b'\x00'
When transferring a class, the operation of generating a class instance is treated as a calling function, and a type check should be added to avoid this problem
a = aclass()
Translated into
a = aclass();
Traceback (most recent call last):
File "C:\Python27\Scripts\pj-script.py", line 6, in
from pkg_resources import load_entry_point
File "c:\python27\lib\site-packages\pkg_resources_init_.py", line 3017, in
@call_aside
File "c:\python27\lib\site-packages\pkg_resources_init.py", line 3003, in
call_aside
f(*args, **kwargs)
File "c:\python27\lib\site-packages\pkg_resources_init.py", line 3030, in
initialize_master_working_set
working_set = WorkingSet.build_master()
File "c:\python27\lib\site-packages\pkg_resources_init.py", line 659, in _
build_master
ws.require(requires)
File "c:\python27\lib\site-packages\pkg_resources_init.py", line 967, in r
equire
needed = self.resolve(parse_requirements(requirements))
File "c:\python27\lib\site-packages\pkg_resources_init_.py", line 853, in r
esolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'dukpy' distribution was not found and i
s required by javascripthon
Currently, this does not work:
a = []
a.append(1) # transpiles to JS as `a.append(1)`, which doesn't work because append is not a JS array function
We need to wrap the variable in a list() call:
a = []
list(a).append(1) # trasnpiles to JS correctly as `a.push(1)`
What do you think about creating a JS array subclass to support native python list functions (append, remove, clear, count....)? Then we can have the JSList
node generate code to create instance of the subclass instead of native JS arrays. I can work on a PR if you are ok with this approach.
I am wondering if pytest-runner is related to the core functionality of javascripthon or not.
But it does give our user an issue where his pip try to download pytest-runner
So, could this dependency be moved to test_require?
Hi all,
Thanks for your great work to blur the boundary of python and javascript. We are using it to transcompile python functions into javascript functions. Now we got a problem with windows machines, where Microsoft prefer '\' over '/'. However, the path separator problem have been nicely fixed on master branch and our build passed if we use your master branch. So could you please share your time schedule for your next release?.
Thanks.
Hi there! This is a very interesting project to me, currently trying to assess if it will solve a problem I have.
When converting some files in my project, I get this error:
$ pj pyinstrument/frame.py
An error occurred while compiling source file 'pyinstrument/frame.py'
TransformationError: Node type 'GeneratorExp': Line: 306, column: 29. No transformation for the node
The line that it's referencing is this:
calculated_time = sum(child.time for child in self.children) + self.absorbed_time
So I guess that's the generator expression. I use them a lot in this project. I guess it might translate like so?
let calculated_time = this.children.map(child => child.time).reduce((a, b) => a+b) + this.absorbed_time
Is there a way to get these generator expressions to convert?
I ran: python3.6 -m metapensiero.pj basic.py
on
https://github.com/OpenMined/PySyft/blob/a127e7155788be4fbff72d234060fb1432ab560d/syft/he/paillier/basic.py
and got An error occurred while compiling source file 'basic.py' UnsupportedSyntaxError: Node type 'Name': Line: 66, column: 63. Name 'float' is reserved in JavaScript.
Which references: https://github.com/OpenMined/PySyft/blob/a127e7155788be4fbff72d234060fb1432ab560d/syft/he/paillier/basic.py#L66
I believe since there is: https://docs.python.org/3/library/functions.html#float what we'd actually want to output from the parser is Number.parseFloat(tensor)
Can we have this support added?
It may happen that your Python code contains statements that are necessary for that Python code to run in Python but aren't required in JS.
Or, for instance, you maybe interested in hinting types in Python using the typing module but you don't want to import that module in JS.
Right now, this:
from typing import List
gets transformed to (es5):
var _typing = require("typing");
The hints are only for the Python code benefits and should be ignored while transpiling.
Could we have come up with a solution so that simple statements are left out?
Is it going to be possible to support **kwargs? For example:
def fun(**kwargs):
print(kwargs)
fun(foo=1)
Installing javascripthon via pip is followed by this error
Collecting javascripthon
Using cached javascripthon-0.8.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-Of3AfA/javascripthon/setup.py", line 14, in <module>
with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
TypeError: 'encoding' is an invalid keyword argument for this function
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-Of3AfA/javascripthon/```
It is empty!
Multi line comments have a col_offset == -1, which is unexpected.
works on
from react import React
Component = React.Component
class MeasureList(Component):
def CommponentWillMount(self):
pass
but not works with
from react import React
class MeasureList(React.Component):
def CommponentWillMount(self):
pass
In JS there isn't an equivalent of the global
statement in Python: in a sense, a variable is automatically put in the global scope when it is not declared, so the following snippet behaves differently when run under Python than under JS:
some_global = None
def get_global():
if some_global:
return some_global
# compute it
some_global = 'foo'
return some_global
Python itself would raise an UnboundLocalError
, while pyflakes reports local variable 'some_global' (defined in enclosing scope on line 1) referenced before assignment
.
So I wonder whether pj
could/should allow me to put a global
statement in that function, adding a null-transform for its node type, in other words simply ignoring the declaration. It would be a bonus if it could even check for the existence of those global(s), just to avoid typos...
Hello, the project seems to be a dream.
As you know, python lacks in front end web development part.
There is a new declarative, JavaScript frontend compiler, which is named Svelte.
I was thinking if we could write the script part of the svelete with python and converts it to JavaScript and have frontend.
Range can have a start, end and step value.
It can be for i in range(5,10):
but it can also be for i in range(10,5,-1):
In that case you would want change the third part of the loop to i += step, instead of i++.
Installing using pip gives error : error: Unable to find vcvarsall.bat
Detailed :
pip install javascripthon
Collecting javascripthon
Using cached javascripthon-0.3.tar.gz
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\users\dr_success\appdata\local\programs\python\python35\lib\site-packages (from javascripthon)
Collecting dukpy (from javascripthon)
Using cached dukpy-0.0.4.tar.gz
Installing collected packages: dukpy, javascripthon
Running setup.py install for dukpy ... error
Complete output from command c:\users\dr_success\appdata\local\programs\python\python35\python.exe -u -c "import setuptools, tokenize;file='C:\Users\DR_SUC1\AppData\Local\Temp\pip-build-u0318qv4\dukpy\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record C:\Users\DR_SUC1\AppData\Local\Temp\pip-l_n4e21_-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.5
creating build\lib.win-amd64-3.5\dukpy
copying dukpy\babel.py -> build\lib.win-amd64-3.5\dukpy
copying dukpy\coffee.py -> build\lib.win-amd64-3.5\dukpy
copying dukpy\evaljs.py -> build\lib.win-amd64-3.5\dukpy
copying dukpy\install.py -> build\lib.win-amd64-3.5\dukpy
copying dukpy\module_loader.py -> build\lib.win-amd64-3.5\dukpy
copying dukpy\tsc.py -> build\lib.win-amd64-3.5\dukpy
copying dukpy__init__.py -> build\lib.win-amd64-3.5\dukpy
creating build\lib.win-amd64-3.5\dukpy\webassets
copying dukpy\webassets\babelfilter.py -> build\lib.win-amd64-3.5\dukpy\webassets
copying dukpy\webassets\typescriptfilter.py -> build\lib.win-amd64-3.5\dukpy\webassets
copying dukpy\webassets__init__.py -> build\lib.win-amd64-3.5\dukpy\webassets
creating build\lib.win-amd64-3.5\dukpy\jsmodules
copying dukpy\jsmodules\babel-6.4.4.min.js -> build\lib.win-amd64-3.5\dukpy\jsmodules
copying dukpy\jsmodules\coffeescript.js -> build\lib.win-amd64-3.5\dukpy\jsmodules
copying dukpy\jsmodules\semver.js -> build\lib.win-amd64-3.5\dukpy\jsmodules
copying dukpy\jsmodules\typescriptServices.js -> build\lib.win-amd64-3.5\dukpy\jsmodules
creating build\lib.win-amd64-3.5\dukpy\jsmodules\react
copying dukpy\jsmodules\react\react-dom-server.js -> build\lib.win-amd64-3.5\dukpy\jsmodules\react
copying dukpy\jsmodules\react\react.js -> build\lib.win-amd64-3.5\dukpy\jsmodules\react
running build_ext
building 'dukpy._dukpy' extension
error: Unable to find vcvarsall.bat
To be VC friendly, PJ could sort the list of imported symbol to avoid spurious diff like the following:
-import {Path, WAMPNode, logging, Message, on_message, register_signals, handler, call} from 'foo';
+import {Message, Path, WAMPNode, call, handler, logging, on_message, register_signals} from 'foo';
Hi: for the sake of clarity, do you assert a GPL license on the translated code? An does it need any GPL-licensed runtime library of yours at runtime?
Thanks!
$ sudo pip install javascripthon
Downloading/unpacking javascripthon
Downloading javascripthon-0.2.tar.gz (55kB): 55kB downloaded
...
Installing collected packages: javascripthon, dukpy
Running setup.py install for javascripthon
Skipping installation of /usr/local/lib/python2.7/dist-packages/metapensiero/__init__.py (namespace package)
File "/usr/local/lib/python2.7/dist-packages/metapensiero/pj/__main__.py", line 49
print(*args, **kwargs)
^
SyntaxError: invalid syntax
File "/usr/local/lib/python2.7/dist-packages/metapensiero/pj/js_ast.py", line 51
yield from self.lines(a.serialize(), delim=True)
^
SyntaxError: invalid syntax
File "/usr/local/lib/python2.7/dist-packages/metapensiero/pj/processor/transforming.py", line 50
yield from a.serialize()
^
SyntaxError: invalid syntax
File "/usr/local/lib/python2.7/dist-packages/metapensiero/pj/processor/util.py", line 275
def __init__(self, node, *items, name=None):
^
SyntaxError: invalid syntax
...
Installing /usr/local/lib/python2.7/dist-packages/javascripthon-0.2-nspkg.pth
Installing pj script to /usr/local/bin
...
pyduktape.c:4:20: fatal error: Python.h: No such file or directory
#include <Python.h>
...
My system:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty
$ python --version
Python 2.7.6
$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
Being given this error when tryin to run python3 -m metapensiero.pj source.py
TransformationError: Node type 'Global': Line: 37, column: 4. No transformation for the node
Obviously this is being caused by my Python file at line 37, column 4, with "Global", are there anywork arounds for this does anyone know, or is there something I can tweak or add to metapensiero.pj to fix this, PS I am new to metapensiero.pj so go easy :)
source.py
to keep it simplesudo pip3 install git+https://github.com/metapensiero/metapensiero.pj
provided by a user on a seperate issuepython3 -m metapensiero.pj source.py
& python3 -m metapensiero.pj -5 source.py
I'm trying to use https://nuxtjs.org/examples/auth-routes#using-the-store and I need to produce import statements like these:
import Vue from 'vue'
import Vuex from 'vuex'
How to achieve this?
Thanks!
When trying to convert this python code:
def binary_search_recursive(array, element, start, end):
if start > end:
return -1
mid = (start + end) // 2
if element == array[mid]:
return mid
if element < array[mid]:
return binary_search_recursive(array, element, start, mid-1)
else:
return binary_search_recursive(array, element, mid+1, end)
An error is thrown, which seems to mean the //
operator in python is not supported:
"An error occurred while compiling source file '/tmp/source/source.py'\r\n" "TransformationError: Node type 'FloorDiv': Line: n. a., column: n. a.. No transformation for the node\r\n"
Would it be possible to support this?
in metapensiero.pj/src/metapensiero/pj/transformations/special.py
# <code>2//3</code> → <code>Math.floor(2/3)</code>
def BinOp_floor(t, x):
if isinstance(x.op, ast.FloorDiv):
return JSCall(
JSAttribute(
JSName('Math'),
'floor'),
JSBinOp(x.left, JSOpDiv(), x.right)
)
BinOp = [BinOp_floor, BinOp_pow, BinOp_default]
[x] Bug (Typo)
unanbiguous
, however expect to see unambiguous
.semanticts
, however expect to see semantics
.crazyest
, however expect to see craziest
.contruct
, however expect to see construct
.threated
, however expect to see treated
.souce
, however expect to see source
.olny
, however expect to see only
.usin
, however expect to see using
.Semi-automated issue generated by
https://github.com/timgates42/meticulous/blob/master/docs/NOTE.md
To avoid wasting CI processing resources a branch with the fix has been
prepared but a pull request has not yet been created. A pull request fixing
the issue can be prepared from the link below, feel free to create it or
request @timgates42 create the PR. Alternatively if the fix is undesired please
close the issue with a small comment about the reasoning.
https://github.com/timgates42/metapensiero.pj/pull/new/bugfix_typos
Thanks.
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
ValueError: Unknown data type received.
ValueError: Unknown data type received.
TransformationError: Node type 'Set': Line: 10, column: 6. No transformation for the node
UnsupportedSyntaxError: Node type 'ClassDef': Line: 6, column: 0. Multiple inheritance is not supported
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.
Automatic conversion of @DataClass decorator to the original class format would be amazing.
For now I had to convert all of my dataclasses back into regular classes before running the script
Created a simple test.py containing
print(2+2)
Then run with
python3 -m metapensiero.pj test.py
And get
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/metapensiero/pj/__main__.py", line 13, in <module>
from . import api
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/metapensiero/pj/api.py", line 16, in <module>
from .processor.transforming import Transformer
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/metapensiero/pj/processor/transforming.py", line 19, in <module>
from .util import (rfilter, parent_of, random_token, Line, Part, obj_source,
File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/metapensiero/pj/processor/util.py", line 59, in <module>
ast.AsyncFunctionDef)
AttributeError: 'module' object has no attribute 'AsyncFunctionDef'
Actually the parameter handling has the following restrictions:
keyword arguments are translated to a destructuring object assignment at the end of the positional parameters list. This is the same for the keywords parameters accumulator which is translated to an object. This means that passing keywords on call is not positionally indifferent: all the preceding positional parameters have to be specified before the keywords.
Because of the previous point, the positional parameters accumulator, the keywords parameters or the keywords accumulator cannot be specified ad the same time. The fact that the keywords container is also positional and the fact that at call time is impossible to distinguish between expected keywords and the others that should be put inside the keyword accumulator forbids that.
The solution to this can be found in something that is "rendered" at translation time only or something that is half rendered and half a runtime feature, but with additional computation cost.
The former may be the rendering a proxy function for every declared function that uses a pre-determined calling convention and the addition of this proxy to the main function object. For each call, render a diverted path that checks for the existence of the proxy and calls it.
The latter would be to render the addition of python-oriented signature metadata to each function and render (maybe optionally) calls to be proxied via an utility function that takes care of handling the parameters according to the exported function signature.
The first solution may clutter the sources with each proxy definition but may be quicker in terms of speed compared to the second solution which may produce cleaner sources but relies on more runtime calculations.
Any other idea?
See title
Python code:
for i in range(3, 1, -1):
Now produces:
for (var i = 3, _pj_a = 1; (i < _pj_a); i += (- 1)) {...}
but should produce (reverse the conditional):
for (var i = 3, _pj_a = 1; (i > _pj_a); i += (- 1))
Seems silly, but when converting this simply stops on these standard and common inbuilt math functions saying Name 'int' is reserved in JavaScript
. Perhaps should simply be parseInt()
and parseFloat()
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.