rapydscript-ns 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/PYTHON_DIFFERENCES_REPORT.md +291 -0
  3. package/PYTHON_FEATURE_COVERAGE.md +96 -5
  4. package/README.md +161 -46
  5. package/TODO.md +2 -283
  6. package/language-service/index.js +4474 -0
  7. package/language-service/language-service.d.ts +40 -0
  8. package/package.json +9 -7
  9. package/src/baselib-builtins.pyj +77 -1
  10. package/src/baselib-containers.pyj +8 -4
  11. package/src/baselib-internal.pyj +30 -1
  12. package/src/baselib-str.pyj +8 -1
  13. package/src/lib/collections.pyj +1 -1
  14. package/src/lib/numpy.pyj +10 -10
  15. package/src/monaco-language-service/analyzer.js +131 -9
  16. package/src/monaco-language-service/builtins.js +12 -2
  17. package/src/monaco-language-service/completions.js +170 -1
  18. package/src/monaco-language-service/diagnostics.js +1 -1
  19. package/src/monaco-language-service/index.js +17 -0
  20. package/src/monaco-language-service/scope.js +3 -0
  21. package/src/output/classes.pyj +20 -3
  22. package/src/output/codegen.pyj +1 -1
  23. package/src/output/functions.pyj +4 -16
  24. package/src/output/loops.pyj +0 -9
  25. package/src/output/modules.pyj +1 -4
  26. package/src/output/operators.pyj +14 -0
  27. package/src/output/stream.pyj +0 -13
  28. package/src/parse.pyj +17 -1
  29. package/test/baselib.pyj +4 -4
  30. package/test/classes.pyj +56 -17
  31. package/test/collections.pyj +5 -5
  32. package/test/python_compat.pyj +326 -0
  33. package/test/python_features.pyj +110 -23
  34. package/test/slice.pyj +105 -0
  35. package/test/str.pyj +25 -0
  36. package/test/unit/fixtures/fibonacci_expected.js +1 -1
  37. package/test/unit/index.js +119 -7
  38. package/test/unit/language-service-builtins.js +70 -0
  39. package/test/unit/language-service-bundle.js +5 -5
  40. package/test/unit/language-service-completions.js +180 -0
  41. package/test/unit/language-service-index.js +350 -0
  42. package/test/unit/language-service-scope.js +255 -0
  43. package/test/unit/language-service.js +35 -0
  44. package/test/unit/run-language-service.js +1 -0
  45. package/test/unit/web-repl.js +134 -0
  46. package/tools/build-language-service.js +2 -2
  47. package/tools/compiler.js +0 -24
  48. package/tools/export.js +3 -37
  49. package/web-repl/rapydscript.js +6 -40
  50. package/web-repl/language-service.js +0 -4187
package/TODO.md CHANGED
@@ -1,9 +1,6 @@
1
1
 
2
2
  ### libraries
3
3
 
4
- - bitburner - handle missed await / concurrency errors gracefully?
5
- - two space tabs
6
-
7
4
  - fix error from vuln report
8
5
  - https://socket.dev/npm/package/rapydscript-ns/alerts/0.8.1?tab=dependencies
9
6
  - https://snyk.io/test/github/ficocelliguy/rapydscript-ns
@@ -12,285 +9,7 @@
12
9
 
13
10
  - vscode plugin based on language service
14
11
 
15
- - export .t.ds for language service
16
-
17
- - add opt-out for python truthyness
18
- - add web-repl flag for python truthiness?
19
- - include python truthiness in compiler call
20
-
21
- - update changelist for 8.0
22
-
23
- I would like you to add support for [ Python's extended subscript syntax where commas inside [] implicitly form a tuple ] to rapydscript. It should have the same syntax as the Python implementation, and be transpiled into equivalent javascript. Please ensure with unit tests that it transpiles and the output JS runs correctly, and that the language service correctly handles it in parsed code. Please make sure it works in the web-repl too. Please also update the README to mention this support.
24
-
25
-
26
-
27
-
28
- Python Feature Gap Report: RapydScript-NS
29
-
30
- Summary
31
-
32
- RapydScript-NS covers the vast majority of Python 2/3 core syntax well. The gaps fall into four categories: modern Python syntax, OOP/protocol features, standard library modules, and semantic
33
- differences.
34
-
35
- ---
36
- 1. Modern Python Syntax (Not Supported)
37
-
38
- ┌───────────────────────────────────────────────┬────────────────┬──────────────────────────────────────────────────────────────┐
39
- │ Feature │ Python Version │ Notes │
40
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
41
- │ match/case (structural pattern matching) │ 3.10+ │ -tested │
42
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
43
- │ Walrus operator := │ 3.8+ │ -tested │
44
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
45
- │ lambda keyword │ all │ -tested │
46
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
47
- │ Variable type annotations x: int = 1 │ 3.6+ │ -tested │
48
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
49
- │ Positional-only parameters (def f(a, /, b):) │ 3.8+ │ -tested │
50
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
51
- │ Keyword-only parameters (def f(a, *, b):) │ 3.0+ │ -tested │
52
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
53
- │ Starred assignment a, *b, c = [1,2,3,4,5] │ 3.0+ │ -tested │
54
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
55
- │ Dict merge literal {**d1, **d2} │ 3.5+ │ -tested │
56
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
57
- │ Parenthesized with (multi-context) │ 3.10+ │ - doesn't make sense in a web context │
58
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
59
- │ Exception chaining raise X from Y │ 3.0+ │ - done │
60
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
61
- │ except* (exception groups) │ 3.11+ │ No support │
62
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
63
- │ Nested comprehensions (for a in b for c in d) │ all │ -tested │
64
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
65
- │ Complex number literals 3+4j │ all │ No j suffix │
66
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
67
- │ Ellipsis literal ... as expression │ all │ -tested │
68
- ├───────────────────────────────────────────────┼────────────────┼──────────────────────────────────────────────────────────────┤
69
- │ b'...' bytes literals │ all │ No b prefix; encoding module exists but no native bytes type │
70
- └───────────────────────────────────────────────┴────────────────┴──────────────────────────────────────────────────────────────┘
71
-
72
- ---
73
- 2. OOP and Dunder Protocol Gaps
74
-
75
- Not Supported at All
76
-
77
- ┌─────────────────────────────────────────┬─────────────────────────────────────────────────────────────────┐
78
- │ Feature │ Notes │
79
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
80
- │ super() │ -tested │
81
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
82
- │ __new__ │ No alternative constructor support │
83
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
84
- │ __del__ │ No destructor/finalizer │
85
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
86
- │ __hash__ │ Explicitly noted as not implemented; set/dict uses === identity │
87
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
88
- │ __bool__ │ Empty [] and {} are truthy in JS (differs from Python) │
89
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
90
- │ __call__ │ Objects cannot be made callable via dunder │
91
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
92
- │ __getattr__ / __setattr__ / __delattr__ │ No attribute access interception │
93
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
94
- │ __getattribute__ │ No attribute lookup overriding │
95
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
96
- │ __format__ │ No custom format() behavior │
97
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
98
- │ __slots__ │ No slot declarations │
99
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
100
- │ __class_getitem__ │ No MyClass[T] generic syntax support │
101
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
102
- │ __init_subclass__ │ No subclass hooks │
103
- ├─────────────────────────────────────────┼─────────────────────────────────────────────────────────────────┤
104
- │ classmethod decorator │ Not tested/documented (may partially work via @staticmethod) │
105
- └─────────────────────────────────────────┴─────────────────────────────────────────────────────────────────┘
106
-
107
- Arithmetic/Comparison Operator Overloading
108
-
109
- All of these dunder methods are not dispatched — operators always use JS native semantics:
110
-
111
- __add__, __radd__, __sub__, __mul__, __truediv__, __floordiv__, __mod__, __pow__, __lt__, __le__, __gt__, __ge__, __ne__, __neg__, __pos__, __abs__, __invert__, __lshift__, __rshift__, __and__,
112
- __or__, __xor__
113
-
114
- (Only __eq__, __contains__, __iter__, __len__, __enter__, __exit__, __repr__, __str__ are dispatched)
115
-
116
- Nested Classes
117
-
118
- Noted in test file (test/classes.pyj) as "not yet fully implemented."
119
-
120
- Abstract Base Classes (ABCs)
121
-
122
- No abc module, no @abstractmethod, no Protocol support.
123
-
124
- ---
125
- 3. Built-in Functions Missing
126
-
127
- ┌──────────────────────────┬────────────────────────────────────────────────┐
128
- │ Function │ Notes │
129
- ├──────────────────────────┼────────────────────────────────────────────────┤
130
- │ super() │ tested │
131
- ├──────────────────────────┼────────────────────────────────────────────────┤
132
- │ issubclass() │ Not implemented │
133
- ├──────────────────────────┼────────────────────────────────────────────────┤
134
- │ hash() │ Not implemented │
135
- ├──────────────────────────┼────────────────────────────────────────────────┤
136
- │ format(value, spec) │ Not listed; str.format() works │
137
- ├──────────────────────────┼────────────────────────────────────────────────┤
138
- │ vars() │ Not listed │
139
- ├──────────────────────────┼────────────────────────────────────────────────┤
140
- │ locals() │ Not listed │
141
- ├──────────────────────────┼────────────────────────────────────────────────┤
142
- │ globals() │ Not listed │
143
- ├──────────────────────────┼────────────────────────────────────────────────┤
144
- │ exec() │ Not listed (JS eval works directly via v'...') │
145
- ├──────────────────────────┼────────────────────────────────────────────────┤
146
- │ eval() │ Not listed │
147
- ├──────────────────────────┼────────────────────────────────────────────────┤
148
- │ compile() │ N/A │
149
- ├──────────────────────────┼────────────────────────────────────────────────┤
150
- │ __import__() │ Not supported │
151
- ├──────────────────────────┼────────────────────────────────────────────────┤
152
- │ input() │ Not built in │
153
- ├──────────────────────────┼────────────────────────────────────────────────┤
154
- │ open() │ Not built in │
155
- ├──────────────────────────┼────────────────────────────────────────────────┤
156
- │ bytes() / bytearray() │ Not built in │
157
- ├──────────────────────────┼────────────────────────────────────────────────┤
158
- │ memoryview() │ N/A (browser context) │
159
- ├──────────────────────────┼────────────────────────────────────────────────┤
160
- │ zip(..., strict=True) │ strict kwarg not supported │
161
- ├──────────────────────────┼────────────────────────────────────────────────┤
162
- │ enumerate(x, start=N) │ start parameter may not be supported │
163
- ├──────────────────────────┼────────────────────────────────────────────────┤
164
- │ all() / any() │ tested │
165
- ├──────────────────────────┼────────────────────────────────────────────────┤
166
- │ next(iter, default?) │ Not listed │
167
- ├──────────────────────────┼────────────────────────────────────────────────┤
168
- │ iter(callable, sentinel) │ Two-arg form likely not supported │
169
- ├──────────────────────────┼────────────────────────────────────────────────┤
170
- │ round(x, ndigits?) │ Not listed │
171
- ├──────────────────────────┼────────────────────────────────────────────────┤
172
- │ slice() │ Not listed as builtin object │
173
- ├──────────────────────────┼────────────────────────────────────────────────┤
174
- │ frozenset() │ Not listed │
175
- ├──────────────────────────┼────────────────────────────────────────────────┤
176
- │ complex() │ Not listed │
177
- ├──────────────────────────┼────────────────────────────────────────────────┤
178
- │ object() │ Not listed │
179
- └──────────────────────────┴────────────────────────────────────────────────┘
180
-
181
- ---
182
- 4. Standard Library Modules Missing
183
-
184
- These are Python stdlib modules with no equivalent in src/lib/:
185
-
186
- ┌─────────────┬─────────────────────────────────────────────────────────────────────────────────┐
187
- │ Module │ What's Missing │
188
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
189
- │ collections │ tested │
190
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
191
- │ functools │ tested │
192
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
193
- │ itertools │ tested │
194
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
195
- │ typing │ List, Dict, Optional, Union, Tuple, Generic, TypeVar, etc. │
196
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
197
- │ dataclasses │ @dataclass, field(), asdict(), astuple() │
198
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
199
- │ contextlib │ contextmanager, suppress, ExitStack, asynccontextmanager │
200
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
201
- │ copy │ copy(), deepcopy() │
202
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
203
- │ string │ Character constants, Template, Formatter │
204
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
205
- │ json │ dumps, loads (JS JSON works directly, but no Python wrapper) │
206
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
207
- │ datetime │ date, time, datetime, timedelta │
208
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
209
- │ inspect │ signature, getmembers, isfunction, etc. │
210
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
211
- │ asyncio │ Event loop, gather, sleep, Queue, Task wrappers │
212
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
213
- │ enum │ Enum, IntEnum, Flag │
214
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
215
- │ abc │ ABC, abstractmethod │
216
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
217
- │ io │ StringIO, BytesIO │
218
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
219
- │ struct │ Binary packing/unpacking │
220
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
221
- │ hashlib │ MD5, SHA-256, etc. │
222
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
223
- │ hmac │ Keyed hashing │
224
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
225
- │ base64 │ (partial — encodings module exists) │
226
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
227
- │ urllib │ URL parsing/encoding (no urllib.parse) │
228
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
229
- │ html │ escape, unescape │
230
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
231
- │ csv │ CSV parsing │
232
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
233
- │ textwrap │ wrap, fill, dedent, indent │
234
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
235
- │ pprint │ Pretty-printing │
236
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
237
- │ logging │ Logging framework │
238
- ├─────────────┼─────────────────────────────────────────────────────────────────────────────────┤
239
- │ unittest │ Test framework (custom runner used instead) │
240
- └─────────────┴─────────────────────────────────────────────────────────────────────────────────┘
241
-
242
- ---
243
- 5. Semantic Differences (Traps)
244
-
245
- These features exist but behave differently from Python:
246
-
247
- ┌─────────────────────────┬────────────────────────────────────────────┬─────────────────────────────────────────────────────────────────────────────────┐
248
- │ Feature │ Python Behavior │ RapydScript Behavior │
249
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
250
- │ Truthiness of [] │ False │ True (JS semantics) │
251
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
252
- │ Truthiness of {} │ False │ True (JS semantics) │
253
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
254
- │ is / is not │ Object identity │ Strict equality === / !== │
255
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
256
- │ // on floats │ math.floor(a/b) │ Correct for integers; JS Math.floor used │
257
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
258
- │ % on negative numbers │ Python modulo (always positive) │ JS remainder (can be negative) │
259
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
260
- │ int / float distinction │ Separate types │ Both are JS number │
261
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
262
- │ String * repetition │ 'a' * 3 == 'aaa' │ Requires pythonize module or JS-side workaround │
263
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
264
- │ sort() / pop() │ Standard list methods │ Renamed to pysort() / pypop() │
265
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
266
- │ Method binding │ Unbound by default, self passed explicitly │ Same — but differs if you store methods in variables without bound_methods flag │
267
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
268
- │ dict key ordering │ Insertion order (3.7+) │ Depends on JS engine (V8: insertion order) │
269
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
270
- │ global scoping │ Full cross-scope declaration │ Partial — interactions with nonlocal can be confusing │
271
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
272
- │ Exception .message │ Not standard (Python uses .args[0]) │ .message is standard (JS style) │
273
- ├─────────────────────────┼────────────────────────────────────────────┼─────────────────────────────────────────────────────────────────────────────────┤
274
- │ re module │ Full PCRE features │ No lookbehind, limited unicode, no (?(1)...) │
275
- └─────────────────────────┴────────────────────────────────────────────┴─────────────────────────────────────────────────────────────────────────────────┘
276
-
277
- ---
278
- Priority Gaps (Most Impactful)
279
-
280
- If prioritizing what to implement next, these have the highest user impact:
281
-
282
- 1. super() — required for idiomatic OOP code - done
283
- 2. Operator overloading (__add__, __lt__, etc.) — blocks numerical/scientific code - done
284
- 3. __bool__ / truthiness fix — silent Python compatibility trap - done
285
- → frozenset — first medium-priority missing builtin - done
286
- 4. lambda keyword — commonly expected - done
287
- 5. all() / any() — extremely common builtins - done
288
- 6. functools.reduce / partial — core functional programming tools - done
289
- 7. collections.defaultdict / Counter — frequently used - done
290
- 8. Nested comprehensions — common Python pattern - done
291
- 9. Walrus operator := — increasingly common in modern Python - done
292
- 10. classmethod decorator — standard OOP pattern - done
293
-
12
+ - examples of using js libraries in rapydscript in readme
294
13
 
295
14
 
296
-
15
+ I would like you to add support for [ [List Concatenation (+) Without overload_operators]() ] to rapydscript. It should have the same syntax as the Python implementation, and be transpiled into equivalent javascript. Please ensure with unit tests that it transpiles and the output JS runs correctly, and that the language service correctly handles it in parsed code. Please make sure it works in the web-repl too. Please also update the README if it has any outdated info about this, and the PYTHON_FEATURE_COVERAGE report.