MCPcopy Index your code
hub / github.com/pyscript/pyscript / _JSModuleProxy

Class _JSModuleProxy

core/src/stdlib/pyscript/context.py:76–104  ·  view source on GitHub ↗

Proxy for JavaScript modules imported via js_modules. This allows Python code to import JavaScript modules using Python's import syntax: ```python from pyscript.js_modules lodash import debounce ``` The proxy lazily retrieves the actual JavaScript module when accessed

Source from the content-addressed store, hash-verified

74
75
76class _JSModuleProxy:
77 """
78 Proxy for JavaScript modules imported via js_modules.
79
80 This allows Python code to import JavaScript modules using Python's
81 import syntax:
82
83 ```python
84 from pyscript.js_modules lodash import debounce
85 ```
86
87 The proxy lazily retrieves the actual JavaScript module when accessed.
88 """
89
90 def __init__(self, name):
91 """
92 Create a proxy for the named JavaScript module.
93 """
94 self.name = name
95
96 def __getattr__(self, field):
97 """
98 Retrieve a JavaScript object/function from the proxied JavaScript
99 module via the given `field` name.
100 """
101 # Avoid Pyodide looking for non-existent special methods.
102 if not field.startswith("_"):
103 return getattr(getattr(js_modules, self.name), field)
104 return None
105
106
107# Register all available JavaScript modules in Python's module system.

Callers 1

context.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected