forked from Distributive-Network/PythonMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
29 lines (26 loc) · 971 Bytes
/
__init__.py
File metadata and controls
29 lines (26 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Export public PythonMonkey APIs
from .pythonmonkey import *
from .helpers import *
from .require import *
# Expose the package version
import importlib.metadata
__version__= importlib.metadata.version(__name__)
del importlib
# Load the module by default to expose global APIs
require("console")
require("base64")
require("timers")
# Add the `.keys()` method on `Object.prototype` to get JSObjectProxy dict() conversion working
# Conversion from a dict-subclass to a strict dict by `dict(subclass)` internally calls the .keys() method to read the dictionary keys,
# but .keys on a JSObjectProxy can only come from the JS side
pythonmonkey.eval("""
(makeList) => {
const keysMethod = {
get() {
return () => makeList(...Object.keys(this))
}
}
Object.defineProperty(Object.prototype, "keys", keysMethod)
Object.defineProperty(Array.prototype, "keys", keysMethod)
}
""", { 'filename': __file__, 'fromPythonFrame': True })(lambda *args: list(args))