rapydscript-ns 0.9.0 → 0.9.2

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 (100) hide show
  1. package/.agignore +1 -1
  2. package/.github/workflows/ci.yml +38 -38
  3. package/=template.pyj +5 -5
  4. package/CHANGELOG.md +10 -0
  5. package/HACKING.md +103 -103
  6. package/LICENSE +24 -24
  7. package/README.md +7 -6
  8. package/TODO.md +116 -1
  9. package/add-toc-to-readme +2 -2
  10. package/bin/export +75 -75
  11. package/bin/rapydscript +70 -70
  12. package/bin/web-repl-export +102 -102
  13. package/build +2 -2
  14. package/language-service/index.js +9 -9
  15. package/language-service/language-service.d.ts +1 -1
  16. package/package.json +6 -2
  17. package/publish.py +37 -37
  18. package/release/compiler.js +246 -231
  19. package/release/signatures.json +23 -23
  20. package/session.vim +4 -4
  21. package/setup.cfg +2 -2
  22. package/src/compiler.pyj +36 -36
  23. package/src/errors.pyj +30 -30
  24. package/src/lib/aes.pyj +646 -646
  25. package/src/lib/contextlib.pyj +379 -0
  26. package/src/lib/copy.pyj +120 -120
  27. package/src/lib/datetime.pyj +712 -0
  28. package/src/lib/elementmaker.pyj +83 -83
  29. package/src/lib/encodings.pyj +126 -126
  30. package/src/lib/gettext.pyj +569 -569
  31. package/src/lib/io.pyj +500 -0
  32. package/src/lib/itertools.pyj +580 -580
  33. package/src/lib/json.pyj +227 -0
  34. package/src/lib/math.pyj +193 -193
  35. package/src/lib/operator.pyj +11 -11
  36. package/src/lib/pythonize.pyj +20 -20
  37. package/src/lib/random.pyj +118 -118
  38. package/src/lib/react.pyj +74 -74
  39. package/src/lib/traceback.pyj +63 -63
  40. package/src/lib/uuid.pyj +77 -77
  41. package/src/monaco-language-service/diagnostics.js +4 -4
  42. package/src/monaco-language-service/dts.js +550 -550
  43. package/src/monaco-language-service/index.js +2 -2
  44. package/src/output/comments.pyj +45 -45
  45. package/src/output/exceptions.pyj +201 -201
  46. package/src/output/jsx.pyj +164 -164
  47. package/src/output/loops.pyj +9 -0
  48. package/src/output/treeshake.pyj +182 -182
  49. package/src/output/utils.pyj +72 -72
  50. package/src/string_interpolation.pyj +72 -72
  51. package/src/tokenizer.pyj +1 -1
  52. package/src/unicode_aliases.pyj +576 -576
  53. package/src/utils.pyj +192 -192
  54. package/test/_import_one.pyj +37 -37
  55. package/test/_import_two/__init__.pyj +11 -11
  56. package/test/_import_two/level2/deep.pyj +4 -4
  57. package/test/_import_two/other.pyj +6 -6
  58. package/test/_import_two/sub.pyj +13 -13
  59. package/test/aes_vectors.pyj +421 -421
  60. package/test/annotations.pyj +80 -80
  61. package/test/contextlib.pyj +362 -0
  62. package/test/datetime.pyj +500 -0
  63. package/test/debugger_stmt.pyj +41 -0
  64. package/test/decorators.pyj +77 -77
  65. package/test/docstrings.pyj +39 -39
  66. package/test/elementmaker_test.pyj +45 -45
  67. package/test/functions.pyj +151 -151
  68. package/test/generators.pyj +41 -41
  69. package/test/generic.pyj +370 -370
  70. package/test/imports.pyj +72 -72
  71. package/test/internationalization.pyj +73 -73
  72. package/test/io.pyj +316 -0
  73. package/test/json.pyj +196 -0
  74. package/test/lint.pyj +164 -164
  75. package/test/loops.pyj +85 -85
  76. package/test/numpy.pyj +734 -734
  77. package/test/omit_function_metadata.pyj +20 -20
  78. package/test/repl.pyj +121 -121
  79. package/test/scoped_flags.pyj +76 -76
  80. package/test/unit/index.js +66 -0
  81. package/test/unit/language-service-dts.js +543 -543
  82. package/test/unit/language-service-hover.js +455 -455
  83. package/test/unit/language-service.js +1 -1
  84. package/test/unit/web-repl.js +533 -0
  85. package/tools/compiler.d.ts +367 -0
  86. package/tools/completer.js +131 -131
  87. package/tools/gettext.js +185 -185
  88. package/tools/ini.js +65 -65
  89. package/tools/msgfmt.js +187 -187
  90. package/tools/repl.js +223 -223
  91. package/tools/test.js +118 -118
  92. package/tools/utils.js +128 -128
  93. package/tools/web_repl.js +95 -95
  94. package/try +41 -41
  95. package/web-repl/env.js +196 -196
  96. package/web-repl/index.html +163 -163
  97. package/web-repl/prism.css +139 -139
  98. package/web-repl/prism.js +113 -113
  99. package/web-repl/rapydscript.js +224 -224
  100. package/web-repl/sha1.js +25 -25
@@ -1,20 +1,20 @@
1
- # globals: RapydScript
2
-
3
- # Test that omit_function_metadata flag suppresses __module__ and __argnames__
4
- code = 'def foo(a, b):\n return a + b'
5
- ast = RapydScript.parse(code, {'filename': '<test>'})
6
-
7
- # Without flag: output should contain __module__ and __argnames__
8
- output_with = v'new RapydScript.OutputStream({"beautify": true, "omit_baselib": true})'
9
- ast.print(output_with)
10
- result_with = output_with.get()
11
- assrt.ok(result_with.indexOf('__module__') >= 0, '__module__ should appear in default output')
12
- assrt.ok(result_with.indexOf('__argnames__') >= 0, '__argnames__ should appear in default output')
13
-
14
- # With flag: output should not contain __module__, __argnames__, or Object.defineProperties
15
- output_without = v'new RapydScript.OutputStream({"beautify": true, "omit_baselib": true, "omit_function_metadata": true})'
16
- ast.print(output_without)
17
- result_without = output_without.get()
18
- assrt.ok(result_without.indexOf('__module__') is -1, '__module__ should not appear when omit_function_metadata is set')
19
- assrt.ok(result_without.indexOf('__argnames__') is -1, '__argnames__ should not appear when omit_function_metadata is set')
20
- assrt.ok(result_without.indexOf('Object.defineProperties') is -1, 'Object.defineProperties should not appear when omit_function_metadata is set')
1
+ # globals: RapydScript
2
+
3
+ # Test that omit_function_metadata flag suppresses __module__ and __argnames__
4
+ code = 'def foo(a, b):\n return a + b'
5
+ ast = RapydScript.parse(code, {'filename': '<test>'})
6
+
7
+ # Without flag: output should contain __module__ and __argnames__
8
+ output_with = v'new RapydScript.OutputStream({"beautify": true, "omit_baselib": true})'
9
+ ast.print(output_with)
10
+ result_with = output_with.get()
11
+ assrt.ok(result_with.indexOf('__module__') >= 0, '__module__ should appear in default output')
12
+ assrt.ok(result_with.indexOf('__argnames__') >= 0, '__argnames__ should appear in default output')
13
+
14
+ # With flag: output should not contain __module__, __argnames__, or Object.defineProperties
15
+ output_without = v'new RapydScript.OutputStream({"beautify": true, "omit_baselib": true, "omit_function_metadata": true})'
16
+ ast.print(output_without)
17
+ result_without = output_without.get()
18
+ assrt.ok(result_without.indexOf('__module__') is -1, '__module__ should not appear when omit_function_metadata is set')
19
+ assrt.ok(result_without.indexOf('__argnames__') is -1, '__argnames__ should not appear when omit_function_metadata is set')
20
+ assrt.ok(result_without.indexOf('Object.defineProperties') is -1, 'Object.defineProperties should not appear when omit_function_metadata is set')
package/test/repl.pyj CHANGED
@@ -1,121 +1,121 @@
1
- # globals: compiler_dir
2
- stdout = []
3
- def clear():
4
- stdout.length = 0
5
-
6
- class FakeConsole:
7
-
8
- def log(self):
9
- Array.prototype.slice.call(arguments).forEach(def (arg):
10
- stdout.push((arg or '').toString())
11
- )
12
- stdout.push('\n')
13
-
14
- def error(self):
15
- Array.prototype.slice.call(arguments).forEach(def (arg):
16
- stdout.push((arg or '').toString())
17
- )
18
- stdout.push('\n')
19
-
20
- class FakeReadline:
21
-
22
- def __init__(self):
23
- self.listeners = {}
24
- self._prompt = ''
25
-
26
- def setPrompt(self, prompt):
27
- self._prompt = prompt
28
-
29
- def write(self, data):
30
- stdout.push(data)
31
-
32
- def clearLine(self):
33
- pass
34
-
35
- def on(self, event, callback):
36
- self.listeners[event] = callback
37
- return self
38
-
39
- def prompt(self):
40
- stdout.push(self._prompt)
41
-
42
- def send_line(self, text):
43
- self.listeners['line'](text)
44
-
45
- repl = require('./repl')
46
- rl = FakeReadline()
47
-
48
- send_line = rl.send_line.bind(rl)
49
-
50
- def send_text(text):
51
- for line in text.split('\n'):
52
- send_line(line)
53
-
54
- def check(text, output):
55
- send_text(text)
56
- eq(output, stdout[0])
57
- clear()
58
-
59
- def check_in(text, output):
60
- send_text(text)
61
- assrt.ok(output in stdout, output + ' not in ' + stdout)
62
- clear()
63
-
64
- def check_not_in(text, output):
65
- send_text(text)
66
- assrt.ok(output not in stdout)
67
- clear()
68
-
69
- readline = {
70
- 'createInterface': def(options):
71
- rl.completer = options.completer
72
- return rl
73
- }
74
- repl({'lib_path':compiler_dir, 'console':FakeConsole(), 'readline':readline, 'terminal':False, 'show_js':False, 'histfile':False})
75
- eq = assrt.equal
76
- eq('>>> ', stdout[-1])
77
- clear()
78
- check('1', '1')
79
- check_in('if 1:\n 2\n \n ', '2')
80
- check_not_in('if 1:\n 2\n ', '2')
81
- check_in('1 +\n1\n\n', '2')
82
- check('max(1, 2)', '2')
83
- send_text(
84
- '''
85
- class A:
86
-
87
- def __init__(self, a):
88
- self. a = a
89
-
90
-
91
- ''')
92
- clear()
93
- check_in('b = A(1)\nb.a', '1')
94
- check_in('c = A(2)\nc.a', '2')
95
- send_text('from __python__ import dict_literals\nd={1:1}')
96
- check_in('isinstance(d, dict)', 'true')
97
- send_text('from __python__ import no_dict_literals\nd={1:1}')
98
- check_in('isinstance(d, dict)', 'false')
99
- # Test completions
100
- def completions(line):
101
- return rl.completer(line)[0]
102
-
103
- def check_completions():
104
- items = completions(arguments[0])
105
- for x in Array.prototype.slice.call(arguments, 1):
106
- assrt.ok(items and x in items, x + ' not in completions for: ' + arguments[0])
107
-
108
- check_completions('', 'return', 'A')
109
- check_completions('Array.', 'isArray', 'apply')
110
- send_text('x = ""\ny = []'), clear()
111
- check_completions('x.', 'substr', 'trim')
112
- check_completions('y.', 'concat', 'push')
113
- check_completions('x.sl', 'slice')
114
- send_text('y = {"x":1}'), clear()
115
- check_completions('y.', 'x')
116
-
117
- # Test docstrings
118
- clear()
119
- send_text('def ds():\n "xxx"\n\n')
120
- clear()
121
- check('ds.__doc__', "'xxx'")
1
+ # globals: compiler_dir
2
+ stdout = []
3
+ def clear():
4
+ stdout.length = 0
5
+
6
+ class FakeConsole:
7
+
8
+ def log(self):
9
+ Array.prototype.slice.call(arguments).forEach(def (arg):
10
+ stdout.push((arg or '').toString())
11
+ )
12
+ stdout.push('\n')
13
+
14
+ def error(self):
15
+ Array.prototype.slice.call(arguments).forEach(def (arg):
16
+ stdout.push((arg or '').toString())
17
+ )
18
+ stdout.push('\n')
19
+
20
+ class FakeReadline:
21
+
22
+ def __init__(self):
23
+ self.listeners = {}
24
+ self._prompt = ''
25
+
26
+ def setPrompt(self, prompt):
27
+ self._prompt = prompt
28
+
29
+ def write(self, data):
30
+ stdout.push(data)
31
+
32
+ def clearLine(self):
33
+ pass
34
+
35
+ def on(self, event, callback):
36
+ self.listeners[event] = callback
37
+ return self
38
+
39
+ def prompt(self):
40
+ stdout.push(self._prompt)
41
+
42
+ def send_line(self, text):
43
+ self.listeners['line'](text)
44
+
45
+ repl = require('./repl')
46
+ rl = FakeReadline()
47
+
48
+ send_line = rl.send_line.bind(rl)
49
+
50
+ def send_text(text):
51
+ for line in text.split('\n'):
52
+ send_line(line)
53
+
54
+ def check(text, output):
55
+ send_text(text)
56
+ eq(output, stdout[0])
57
+ clear()
58
+
59
+ def check_in(text, output):
60
+ send_text(text)
61
+ assrt.ok(output in stdout, output + ' not in ' + stdout)
62
+ clear()
63
+
64
+ def check_not_in(text, output):
65
+ send_text(text)
66
+ assrt.ok(output not in stdout)
67
+ clear()
68
+
69
+ readline = {
70
+ 'createInterface': def(options):
71
+ rl.completer = options.completer
72
+ return rl
73
+ }
74
+ repl({'lib_path':compiler_dir, 'console':FakeConsole(), 'readline':readline, 'terminal':False, 'show_js':False, 'histfile':False})
75
+ eq = assrt.equal
76
+ eq('>>> ', stdout[-1])
77
+ clear()
78
+ check('1', '1')
79
+ check_in('if 1:\n 2\n \n ', '2')
80
+ check_not_in('if 1:\n 2\n ', '2')
81
+ check_in('1 +\n1\n\n', '2')
82
+ check('max(1, 2)', '2')
83
+ send_text(
84
+ '''
85
+ class A:
86
+
87
+ def __init__(self, a):
88
+ self. a = a
89
+
90
+
91
+ ''')
92
+ clear()
93
+ check_in('b = A(1)\nb.a', '1')
94
+ check_in('c = A(2)\nc.a', '2')
95
+ send_text('from __python__ import dict_literals\nd={1:1}')
96
+ check_in('isinstance(d, dict)', 'true')
97
+ send_text('from __python__ import no_dict_literals\nd={1:1}')
98
+ check_in('isinstance(d, dict)', 'false')
99
+ # Test completions
100
+ def completions(line):
101
+ return rl.completer(line)[0]
102
+
103
+ def check_completions():
104
+ items = completions(arguments[0])
105
+ for x in Array.prototype.slice.call(arguments, 1):
106
+ assrt.ok(items and x in items, x + ' not in completions for: ' + arguments[0])
107
+
108
+ check_completions('', 'return', 'A')
109
+ check_completions('Array.', 'isArray', 'apply')
110
+ send_text('x = ""\ny = []'), clear()
111
+ check_completions('x.', 'substr', 'trim')
112
+ check_completions('y.', 'concat', 'push')
113
+ check_completions('x.sl', 'slice')
114
+ send_text('y = {"x":1}'), clear()
115
+ check_completions('y.', 'x')
116
+
117
+ # Test docstrings
118
+ clear()
119
+ send_text('def ds():\n "xxx"\n\n')
120
+ clear()
121
+ check('ds.__doc__', "'xxx'")
@@ -1,76 +1,76 @@
1
- # vim:fileencoding=utf-8
2
- # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
-
4
- a = {1:1}
5
- assrt.ok(not isinstance(a, dict))
6
-
7
- from __python__ import dict_literals, overload_getitem
8
- a = {1:1}
9
- assrt.ok(isinstance(a, dict))
10
- assrt.equal(a[1], 1)
11
- a[2] = 2
12
- assrt.equal(a[2], 2)
13
- a[2] += 4
14
- assrt.equal(a[2], 6)
15
- assrt.deepEqual(list(a.keys()), [1, 2])
16
- from __python__ import no_dict_literals, no_overload_getitem
17
-
18
-
19
- a = {1:1}
20
- assrt.ok(not isinstance(a, dict))
21
-
22
- def f():
23
- from __python__ import dict_literals
24
- a = {1:1}
25
- assrt.ok(isinstance(a, dict))
26
-
27
- a = {1:1}
28
- assrt.ok(not isinstance(a, dict))
29
-
30
- class S:
31
- from __python__ import bound_methods
32
-
33
- def __init__(self):
34
- self.a = 3
35
-
36
- def val(self):
37
- return self.a if self else None
38
-
39
- f = S().val
40
- assrt.equal(f(), S().val())
41
-
42
- class U:
43
-
44
- def __init__(self):
45
- self.a = 3
46
-
47
- def val(self):
48
- return self.a if self else None
49
-
50
- f = U().val
51
- assrt.equal(f(), None)
52
-
53
- class C:
54
-
55
- def __init__(self):
56
- self.a = 3
57
-
58
- def uval1(self):
59
- return self.a if self else None
60
-
61
- from __python__ import bound_methods
62
-
63
- def bval(self):
64
- return self.a
65
-
66
- from __python__ import no_bound_methods
67
-
68
- def uval2(self):
69
- return self.a if self else None
70
-
71
- c = C()
72
- u1, u2 = c.uval1, c.uval2
73
- f = c.bval
74
- assrt.equal(u1(), None)
75
- assrt.equal(u2(), None)
76
- assrt.equal(f(), 3)
1
+ # vim:fileencoding=utf-8
2
+ # License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
3
+
4
+ a = {1:1}
5
+ assrt.ok(not isinstance(a, dict))
6
+
7
+ from __python__ import dict_literals, overload_getitem
8
+ a = {1:1}
9
+ assrt.ok(isinstance(a, dict))
10
+ assrt.equal(a[1], 1)
11
+ a[2] = 2
12
+ assrt.equal(a[2], 2)
13
+ a[2] += 4
14
+ assrt.equal(a[2], 6)
15
+ assrt.deepEqual(list(a.keys()), [1, 2])
16
+ from __python__ import no_dict_literals, no_overload_getitem
17
+
18
+
19
+ a = {1:1}
20
+ assrt.ok(not isinstance(a, dict))
21
+
22
+ def f():
23
+ from __python__ import dict_literals
24
+ a = {1:1}
25
+ assrt.ok(isinstance(a, dict))
26
+
27
+ a = {1:1}
28
+ assrt.ok(not isinstance(a, dict))
29
+
30
+ class S:
31
+ from __python__ import bound_methods
32
+
33
+ def __init__(self):
34
+ self.a = 3
35
+
36
+ def val(self):
37
+ return self.a if self else None
38
+
39
+ f = S().val
40
+ assrt.equal(f(), S().val())
41
+
42
+ class U:
43
+
44
+ def __init__(self):
45
+ self.a = 3
46
+
47
+ def val(self):
48
+ return self.a if self else None
49
+
50
+ f = U().val
51
+ assrt.equal(f(), None)
52
+
53
+ class C:
54
+
55
+ def __init__(self):
56
+ self.a = 3
57
+
58
+ def uval1(self):
59
+ return self.a if self else None
60
+
61
+ from __python__ import bound_methods
62
+
63
+ def bval(self):
64
+ return self.a
65
+
66
+ from __python__ import no_bound_methods
67
+
68
+ def uval2(self):
69
+ return self.a if self else None
70
+
71
+ c = C()
72
+ u1, u2 = c.uval1, c.uval2
73
+ f = c.bval
74
+ assrt.equal(u1(), None)
75
+ assrt.equal(u2(), None)
76
+ assrt.equal(f(), 3)
@@ -5227,6 +5227,72 @@ assrt.equal(fib(15), 610)
5227
5227
  },
5228
5228
  },
5229
5229
 
5230
+ // ── Strict-mode var declarations ─────────────────────────────────────
5231
+
5232
+ {
5233
+ name: "comprehension_unpack_var_declared",
5234
+ description: "list comprehension with tuple unpacking declares var ρσ_unpack",
5235
+ src: [
5236
+ "# globals: assrt",
5237
+ "pairs = [('a', 1), ('b', 2), ('c', 3)]",
5238
+ "result = [v for k, v in pairs if k != 'b']",
5239
+ "assrt.deepEqual(result, [1, 3])",
5240
+ ].join("\n"),
5241
+ js_checks: [/var\s[^;]*ρσ_unpack/],
5242
+ },
5243
+
5244
+ {
5245
+ name: "comprehension_unpack_nested_clauses",
5246
+ description: "nested comprehension with tuple unpacking in inner clause declares ρσ_unpack",
5247
+ src: [
5248
+ "# globals: assrt",
5249
+ "groups = [[(1, 'a'), (2, 'b')], [(3, 'c')]]",
5250
+ "result = [s for row in groups for n, s in row]",
5251
+ "assrt.deepEqual(result, ['a', 'b', 'c'])",
5252
+ ].join("\n"),
5253
+ js_checks: [/var\s[^;]*ρσ_unpack/],
5254
+ },
5255
+
5256
+ {
5257
+ name: "with_statement_scope_declared",
5258
+ description: "with statement ρσ_with_exception/ρσ_with_suppress are scope-declared (not implicit globals)",
5259
+ src: [
5260
+ "# globals: assrt",
5261
+ "class CM:",
5262
+ " def __init__(self):",
5263
+ " self.entered = False",
5264
+ " self.exited = False",
5265
+ " def __enter__(self):",
5266
+ " self.entered = True",
5267
+ " return self",
5268
+ " def __exit__(self, exc_type, exc_val, exc_tb):",
5269
+ " self.exited = True",
5270
+ " return False",
5271
+ "with CM() as c:",
5272
+ " assrt.ok(c.entered)",
5273
+ "assrt.ok(c.exited)",
5274
+ ].join("\n"),
5275
+ js_checks: [/let\s[^;]*ρσ_with_exception/, /let\s[^;]*ρσ_with_suppress/],
5276
+ },
5277
+
5278
+ {
5279
+ name: "with_statement_suppresses_exception",
5280
+ description: "with statement __exit__ returning True suppresses the exception",
5281
+ src: [
5282
+ "# globals: assrt",
5283
+ "class Suppressor:",
5284
+ " def __enter__(self):",
5285
+ " return self",
5286
+ " def __exit__(self, exc_type, exc_val, exc_tb):",
5287
+ " return True",
5288
+ "caught = False",
5289
+ "with Suppressor():",
5290
+ " raise ValueError('boom')",
5291
+ " caught = True # should not reach",
5292
+ "assrt.ok(not caught, 'line after raise should not execute')",
5293
+ ].join("\n"),
5294
+ },
5295
+
5230
5296
  ];
5231
5297
 
5232
5298
  // ── Runner ───────────────────────────────────────────────────────────────────