rapydscript-ns 0.8.2 → 0.8.4
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.
- package/.agignore +1 -1
- package/.github/workflows/ci.yml +38 -38
- package/=template.pyj +5 -5
- package/CHANGELOG.md +39 -0
- package/HACKING.md +103 -103
- package/LICENSE +24 -24
- package/PYTHON_DIFFERENCES_REPORT.md +291 -0
- package/PYTHON_FEATURE_COVERAGE.md +106 -15
- package/README.md +831 -52
- package/TODO.md +4 -286
- package/add-toc-to-readme +2 -2
- package/bin/export +75 -75
- package/bin/rapydscript +70 -70
- package/bin/web-repl-export +102 -102
- package/build +2 -2
- package/language-service/index.js +4623 -0
- package/language-service/language-service.d.ts +40 -0
- package/package.json +9 -7
- package/publish.py +37 -37
- package/release/baselib-plain-pretty.js +2006 -229
- package/release/baselib-plain-ugly.js +70 -3
- package/release/compiler.js +11554 -3870
- package/release/signatures.json +31 -29
- package/session.vim +4 -4
- package/setup.cfg +2 -2
- package/src/ast.pyj +93 -1
- package/src/baselib-builtins.pyj +99 -2
- package/src/baselib-containers.pyj +107 -4
- package/src/baselib-errors.pyj +44 -0
- package/src/baselib-internal.pyj +124 -5
- package/src/baselib-itertools.pyj +97 -97
- package/src/baselib-str.pyj +32 -1
- package/src/compiler.pyj +36 -36
- package/src/errors.pyj +30 -30
- package/src/lib/aes.pyj +646 -646
- package/src/lib/collections.pyj +1 -1
- package/src/lib/copy.pyj +120 -0
- package/src/lib/elementmaker.pyj +83 -83
- package/src/lib/encodings.pyj +126 -126
- package/src/lib/gettext.pyj +569 -569
- package/src/lib/itertools.pyj +580 -580
- package/src/lib/math.pyj +193 -193
- package/src/lib/numpy.pyj +10 -10
- package/src/lib/operator.pyj +11 -11
- package/src/lib/pythonize.pyj +20 -20
- package/src/lib/random.pyj +118 -118
- package/src/lib/re.pyj +470 -470
- package/src/lib/react.pyj +74 -0
- package/src/lib/traceback.pyj +63 -63
- package/src/lib/uuid.pyj +77 -77
- package/src/monaco-language-service/analyzer.js +131 -9
- package/src/monaco-language-service/builtins.js +17 -2
- package/src/monaco-language-service/completions.js +170 -1
- package/src/monaco-language-service/diagnostics.js +25 -3
- package/src/monaco-language-service/dts.js +550 -550
- package/src/monaco-language-service/index.js +17 -0
- package/src/monaco-language-service/scope.js +3 -0
- package/src/output/classes.pyj +128 -11
- package/src/output/codegen.pyj +17 -3
- package/src/output/comments.pyj +45 -45
- package/src/output/exceptions.pyj +201 -105
- package/src/output/functions.pyj +13 -16
- package/src/output/jsx.pyj +164 -0
- package/src/output/literals.pyj +28 -2
- package/src/output/loops.pyj +0 -9
- package/src/output/modules.pyj +2 -5
- package/src/output/operators.pyj +22 -2
- package/src/output/statements.pyj +2 -2
- package/src/output/stream.pyj +1 -13
- package/src/output/treeshake.pyj +182 -182
- package/src/output/utils.pyj +72 -72
- package/src/parse.pyj +434 -114
- package/src/string_interpolation.pyj +72 -72
- package/src/tokenizer.pyj +29 -0
- package/src/unicode_aliases.pyj +576 -576
- package/src/utils.pyj +192 -192
- package/test/_import_one.pyj +37 -37
- package/test/_import_two/__init__.pyj +11 -11
- package/test/_import_two/level2/deep.pyj +4 -4
- package/test/_import_two/other.pyj +6 -6
- package/test/_import_two/sub.pyj +13 -13
- package/test/aes_vectors.pyj +421 -421
- package/test/annotations.pyj +80 -80
- package/test/baselib.pyj +4 -4
- package/test/classes.pyj +56 -17
- package/test/collections.pyj +5 -5
- package/test/decorators.pyj +77 -77
- package/test/docstrings.pyj +39 -39
- package/test/elementmaker_test.pyj +45 -45
- package/test/functions.pyj +151 -151
- package/test/generators.pyj +41 -41
- package/test/generic.pyj +370 -370
- package/test/imports.pyj +72 -72
- package/test/internationalization.pyj +73 -73
- package/test/lint.pyj +164 -164
- package/test/loops.pyj +85 -85
- package/test/numpy.pyj +734 -734
- package/test/omit_function_metadata.pyj +20 -20
- package/test/python_compat.pyj +326 -0
- package/test/python_features.pyj +129 -29
- package/test/regexp.pyj +55 -55
- package/test/repl.pyj +121 -121
- package/test/scoped_flags.pyj +76 -76
- package/test/slice.pyj +105 -0
- package/test/str.pyj +25 -0
- package/test/unit/fixtures/fibonacci_expected.js +1 -1
- package/test/unit/index.js +2296 -71
- package/test/unit/language-service-builtins.js +70 -0
- package/test/unit/language-service-bundle.js +5 -5
- package/test/unit/language-service-completions.js +180 -0
- package/test/unit/language-service-dts.js +543 -543
- package/test/unit/language-service-hover.js +455 -455
- package/test/unit/language-service-index.js +350 -0
- package/test/unit/language-service-scope.js +255 -0
- package/test/unit/language-service.js +625 -4
- package/test/unit/run-language-service.js +1 -0
- package/test/unit/web-repl.js +437 -0
- package/tools/build-language-service.js +2 -2
- package/tools/cli.js +547 -547
- package/tools/compile.js +219 -219
- package/tools/compiler.js +0 -24
- package/tools/completer.js +131 -131
- package/tools/embedded_compiler.js +251 -251
- package/tools/export.js +3 -37
- package/tools/gettext.js +185 -185
- package/tools/ini.js +65 -65
- package/tools/msgfmt.js +187 -187
- package/tools/repl.js +223 -223
- package/tools/test.js +118 -118
- package/tools/utils.js +128 -128
- package/tools/web_repl.js +95 -95
- package/try +41 -41
- package/web-repl/env.js +196 -74
- package/web-repl/index.html +163 -163
- package/web-repl/main.js +252 -254
- package/web-repl/prism.css +139 -139
- package/web-repl/prism.js +113 -113
- package/web-repl/rapydscript.js +227 -139
- package/web-repl/sha1.js +25 -25
- package/hack_demo.pyj +0 -112
- package/web-repl/language-service.js +0 -4187
package/test/annotations.pyj
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
def add(a: int, b: float):
|
|
2
|
-
return a + b
|
|
3
|
-
|
|
4
|
-
assrt.ok(add.__annotations__)
|
|
5
|
-
assrt.equal(add.__annotations__['a'], int)
|
|
6
|
-
assrt.equal(add.__annotations__['b'], float)
|
|
7
|
-
assrt.equal(add.__annotations__['return'], undefined)
|
|
8
|
-
|
|
9
|
-
def sum(ls: list) -> int:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
assrt.ok(not (sum.__annotations__ == undefined))
|
|
13
|
-
assrt.deepEqual(sum.__annotations__, {
|
|
14
|
-
'ls': list,
|
|
15
|
-
'return': int
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
def optional(a:int=10):
|
|
19
|
-
return a
|
|
20
|
-
|
|
21
|
-
assrt.ok(not (optional.__annotations__ == undefined))
|
|
22
|
-
assrt.equal(optional.__annotations__.a, int)
|
|
23
|
-
assrt.equal(optional.__defaults__.a, 10)
|
|
24
|
-
|
|
25
|
-
def otherexpr(a:3+4) -> [1, 2]:
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
assrt.ok(not (otherexpr.__annotations__ == undefined))
|
|
29
|
-
assrt.equal(otherexpr.__annotations__['a'], 7)
|
|
30
|
-
assrt.deepEqual(otherexpr.__annotations__['return'], [1, 2])
|
|
31
|
-
|
|
32
|
-
def basic(x:float):
|
|
33
|
-
pass
|
|
34
|
-
|
|
35
|
-
assrt.deepEqual(basic.__annotations__, {
|
|
36
|
-
'x': float
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
def kwstarargs(*args:list, **kwargs:dict) -> int:
|
|
40
|
-
pass
|
|
41
|
-
|
|
42
|
-
assrt.equal(kwstarargs.__annotations__['return'], int)
|
|
43
|
-
|
|
44
|
-
def nothing():
|
|
45
|
-
pass
|
|
46
|
-
|
|
47
|
-
assrt.ok(nothing.__annotations__ == undefined)
|
|
48
|
-
assrt.throws(def():
|
|
49
|
-
nothing.__annotations__['return']
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
test = def(x: int):
|
|
53
|
-
pass
|
|
54
|
-
|
|
55
|
-
assrt.deepEqual(test.__annotations__, {
|
|
56
|
-
'x': int
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
anonreturn = def() -> 'test':
|
|
60
|
-
pass
|
|
61
|
-
|
|
62
|
-
assrt.equal(anonreturn.__annotations__['return'], 'test')
|
|
63
|
-
|
|
64
|
-
assrt.equal(def asexpr(a: int):
|
|
65
|
-
a
|
|
66
|
-
.__annotations__['a'], int)
|
|
67
|
-
|
|
68
|
-
assrt.deepEqual(def(a: int) -> float:
|
|
69
|
-
a + 10.0
|
|
70
|
-
.__annotations__, {
|
|
71
|
-
'a': int,
|
|
72
|
-
'return': float
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
class A:
|
|
76
|
-
|
|
77
|
-
def f(self, a : int, b: 'x') -> float:
|
|
78
|
-
pass
|
|
79
|
-
|
|
80
|
-
assrt.deepEqual(A.prototype.f.__annotations__, {'a':int, 'b':'x', 'return': float})
|
|
1
|
+
def add(a: int, b: float):
|
|
2
|
+
return a + b
|
|
3
|
+
|
|
4
|
+
assrt.ok(add.__annotations__)
|
|
5
|
+
assrt.equal(add.__annotations__['a'], int)
|
|
6
|
+
assrt.equal(add.__annotations__['b'], float)
|
|
7
|
+
assrt.equal(add.__annotations__['return'], undefined)
|
|
8
|
+
|
|
9
|
+
def sum(ls: list) -> int:
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
assrt.ok(not (sum.__annotations__ == undefined))
|
|
13
|
+
assrt.deepEqual(sum.__annotations__, {
|
|
14
|
+
'ls': list,
|
|
15
|
+
'return': int
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
def optional(a:int=10):
|
|
19
|
+
return a
|
|
20
|
+
|
|
21
|
+
assrt.ok(not (optional.__annotations__ == undefined))
|
|
22
|
+
assrt.equal(optional.__annotations__.a, int)
|
|
23
|
+
assrt.equal(optional.__defaults__.a, 10)
|
|
24
|
+
|
|
25
|
+
def otherexpr(a:3+4) -> [1, 2]:
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
assrt.ok(not (otherexpr.__annotations__ == undefined))
|
|
29
|
+
assrt.equal(otherexpr.__annotations__['a'], 7)
|
|
30
|
+
assrt.deepEqual(otherexpr.__annotations__['return'], [1, 2])
|
|
31
|
+
|
|
32
|
+
def basic(x:float):
|
|
33
|
+
pass
|
|
34
|
+
|
|
35
|
+
assrt.deepEqual(basic.__annotations__, {
|
|
36
|
+
'x': float
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
def kwstarargs(*args:list, **kwargs:dict) -> int:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
assrt.equal(kwstarargs.__annotations__['return'], int)
|
|
43
|
+
|
|
44
|
+
def nothing():
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
assrt.ok(nothing.__annotations__ == undefined)
|
|
48
|
+
assrt.throws(def():
|
|
49
|
+
nothing.__annotations__['return']
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
test = def(x: int):
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
assrt.deepEqual(test.__annotations__, {
|
|
56
|
+
'x': int
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
anonreturn = def() -> 'test':
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
assrt.equal(anonreturn.__annotations__['return'], 'test')
|
|
63
|
+
|
|
64
|
+
assrt.equal(def asexpr(a: int):
|
|
65
|
+
a
|
|
66
|
+
.__annotations__['a'], int)
|
|
67
|
+
|
|
68
|
+
assrt.deepEqual(def(a: int) -> float:
|
|
69
|
+
a + 10.0
|
|
70
|
+
.__annotations__, {
|
|
71
|
+
'a': int,
|
|
72
|
+
'return': float
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
class A:
|
|
76
|
+
|
|
77
|
+
def f(self, a : int, b: 'x') -> float:
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
assrt.deepEqual(A.prototype.f.__annotations__, {'a':int, 'b':'x', 'return': float})
|
package/test/baselib.pyj
CHANGED
|
@@ -117,8 +117,8 @@ assrt.throws(def():a.index(8);, ValueError)
|
|
|
117
117
|
assrt.throws(def():a.index(1, 1);, ValueError)
|
|
118
118
|
assrt.throws(def():a.index(4, 1, 2);, ValueError)
|
|
119
119
|
assrt.equal(1, a.index(2, 1, 2))
|
|
120
|
-
assrt.throws(def():a.
|
|
121
|
-
assrt.equal(a.
|
|
120
|
+
assrt.throws(def():a.pop(10);, IndexError)
|
|
121
|
+
assrt.equal(a.pop(-1), 4)
|
|
122
122
|
assrt.deepEqual(a, [1,2,3])
|
|
123
123
|
assrt.equal(a.remove(2), None)
|
|
124
124
|
assrt.deepEqual(a, [1, 3])
|
|
@@ -141,9 +141,9 @@ assrt.ok(a.as_array().extend == undefined)
|
|
|
141
141
|
a = [1, 2, 1]
|
|
142
142
|
assrt.equal(a.count(1), 2)
|
|
143
143
|
a = [3, 2, 4, 1]
|
|
144
|
-
a.
|
|
144
|
+
a.sort()
|
|
145
145
|
assrt.deepEqual(a, [1,2,3,4])
|
|
146
|
-
a.
|
|
146
|
+
a.sort(reverse=True)
|
|
147
147
|
assrt.deepEqual(a, [4,3,2,1])
|
|
148
148
|
assrt.deepEqual(a, a.slice())
|
|
149
149
|
assrt.ok(a is not a.slice())
|
package/test/classes.pyj
CHANGED
|
@@ -67,7 +67,7 @@ bound = angela.get_bound_method()
|
|
|
67
67
|
assrt.equal(bound(), angela.how_long())
|
|
68
68
|
|
|
69
69
|
# function methods
|
|
70
|
-
assrt.deepEqual(dir(angela)
|
|
70
|
+
assrt.deepEqual(sorted(dir(angela)), [
|
|
71
71
|
'HAIRS',
|
|
72
72
|
"__init__",
|
|
73
73
|
'__repr__',
|
|
@@ -137,22 +137,61 @@ inc()
|
|
|
137
137
|
assrt.equal(c.count, 6)
|
|
138
138
|
|
|
139
139
|
# nested classes
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
140
|
+
class Molecule:
|
|
141
|
+
class Atom:
|
|
142
|
+
def __init__(self, element):
|
|
143
|
+
self.element = element
|
|
144
|
+
def __repr__(self):
|
|
145
|
+
return 'Atom(' + self.element + ')'
|
|
146
|
+
|
|
147
|
+
def __init__(self, elements):
|
|
148
|
+
self.structure = []
|
|
149
|
+
for e in elements:
|
|
150
|
+
self.structure.push(Molecule.Atom(e))
|
|
151
|
+
|
|
152
|
+
water = Molecule(['H', 'H', 'O'])
|
|
153
|
+
assrt.equal(len(water.structure), 3)
|
|
154
|
+
assrt.equal(water.structure[0].element, 'H')
|
|
155
|
+
assrt.equal(water.structure[2].element, 'O')
|
|
156
|
+
for atom in water.structure:
|
|
157
|
+
assrt.ok(isinstance(atom, Molecule.Atom))
|
|
158
|
+
|
|
159
|
+
# nested class accessible via class reference and via instance attribute
|
|
160
|
+
assrt.ok(Molecule.Atom is water.structure[0].__class__)
|
|
161
|
+
# nested class can also be accessed via instance (self.Inner semantics)
|
|
162
|
+
mol2 = Molecule(['C'])
|
|
163
|
+
assrt.ok(isinstance(mol2.structure[0], mol2.Atom))
|
|
164
|
+
|
|
165
|
+
# two levels of nesting
|
|
166
|
+
class Universe:
|
|
167
|
+
class Galaxy:
|
|
168
|
+
class Star:
|
|
169
|
+
def __init__(self, name):
|
|
170
|
+
self.name = name
|
|
171
|
+
def __init__(self, star_name):
|
|
172
|
+
self.star = Universe.Galaxy.Star(star_name)
|
|
173
|
+
def __init__(self, star_name):
|
|
174
|
+
self.galaxy = Universe.Galaxy(star_name)
|
|
175
|
+
|
|
176
|
+
u = Universe('Sol')
|
|
177
|
+
assrt.equal(u.galaxy.star.name, 'Sol')
|
|
178
|
+
assrt.ok(isinstance(u.galaxy.star, Universe.Galaxy.Star))
|
|
179
|
+
|
|
180
|
+
# nested class with inheritance from outer-scope class
|
|
181
|
+
class Animal:
|
|
182
|
+
def __init__(self, sound):
|
|
183
|
+
self.sound = sound
|
|
184
|
+
|
|
185
|
+
class Zoo:
|
|
186
|
+
class Dog(Animal):
|
|
187
|
+
def __init__(self):
|
|
188
|
+
Animal.__init__(self, 'woof')
|
|
189
|
+
|
|
190
|
+
zoo = Zoo()
|
|
191
|
+
fido = Zoo.Dog()
|
|
192
|
+
assrt.equal(fido.sound, 'woof')
|
|
193
|
+
assrt.ok(isinstance(fido, Animal))
|
|
194
|
+
assrt.ok(isinstance(fido, Zoo.Dog))
|
|
156
195
|
|
|
157
196
|
# starargs and method decorators
|
|
158
197
|
def negate(fn):
|
package/test/collections.pyj
CHANGED
|
@@ -62,18 +62,18 @@ assrt.equal(s[4:1:-2], 'ec')
|
|
|
62
62
|
|
|
63
63
|
# sorting
|
|
64
64
|
a = [2,1,3]
|
|
65
|
-
a.
|
|
65
|
+
a.sort(key=def(x):return 0;)
|
|
66
66
|
assrt.deepEqual(a, [2,1,3]) # stable sort
|
|
67
|
-
a.
|
|
67
|
+
a.sort(reverse=True)
|
|
68
68
|
assrt.deepEqual(a, [3,2,1])
|
|
69
|
-
a.
|
|
69
|
+
a.sort()
|
|
70
70
|
assrt.deepEqual(a, [1,2,3])
|
|
71
71
|
|
|
72
72
|
# misc interface
|
|
73
73
|
a = [1,2,3]
|
|
74
|
-
assrt.equal(a.
|
|
74
|
+
assrt.equal(a.pop(), 3)
|
|
75
75
|
assrt.deepEqual(a, [1,2])
|
|
76
|
-
assrt.equal(a.
|
|
76
|
+
assrt.equal(a.pop(0), 1)
|
|
77
77
|
assrt.deepEqual(a, [2])
|
|
78
78
|
|
|
79
79
|
# strings
|
package/test/decorators.pyj
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
# vim:fileencoding=utf-8
|
|
2
|
-
# License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
-
|
|
4
|
-
def double(f):
|
|
5
|
-
return def (x):
|
|
6
|
-
return 2 * f(x)
|
|
7
|
-
|
|
8
|
-
def triple(f):
|
|
9
|
-
return def(x):
|
|
10
|
-
return 3 * f(x)
|
|
11
|
-
|
|
12
|
-
@double
|
|
13
|
-
def half(x):
|
|
14
|
-
return x // 2
|
|
15
|
-
|
|
16
|
-
@double
|
|
17
|
-
def f1(x):
|
|
18
|
-
return x
|
|
19
|
-
|
|
20
|
-
@double
|
|
21
|
-
@triple
|
|
22
|
-
def f2(x):
|
|
23
|
-
return x
|
|
24
|
-
|
|
25
|
-
def append_one(f):
|
|
26
|
-
return def(x):
|
|
27
|
-
ans = f(x)
|
|
28
|
-
ans.push(1)
|
|
29
|
-
return ans
|
|
30
|
-
|
|
31
|
-
def append_two(f):
|
|
32
|
-
return def(x):
|
|
33
|
-
ans = f(x)
|
|
34
|
-
ans.push(2)
|
|
35
|
-
return ans
|
|
36
|
-
|
|
37
|
-
@append_two
|
|
38
|
-
@append_one
|
|
39
|
-
def f3():
|
|
40
|
-
return []
|
|
41
|
-
|
|
42
|
-
o = {'double':double}
|
|
43
|
-
|
|
44
|
-
@o.double
|
|
45
|
-
def f4():
|
|
46
|
-
return 1
|
|
47
|
-
|
|
48
|
-
assrt.equal(2, half(2))
|
|
49
|
-
assrt.equal(4, f1(2))
|
|
50
|
-
assrt.equal(12, f2(2))
|
|
51
|
-
assrt.equal(2, f4())
|
|
52
|
-
assrt.deepEqual([1, 2], f3())
|
|
53
|
-
|
|
54
|
-
def multiply(amt):
|
|
55
|
-
|
|
56
|
-
def wrapper(f):
|
|
57
|
-
return def ():
|
|
58
|
-
return amt * f()
|
|
59
|
-
|
|
60
|
-
return wrapper
|
|
61
|
-
|
|
62
|
-
@multiply(2)
|
|
63
|
-
def two():
|
|
64
|
-
return 1
|
|
65
|
-
|
|
66
|
-
@multiply(3)
|
|
67
|
-
def three():
|
|
68
|
-
return 1
|
|
69
|
-
|
|
70
|
-
@multiply(2)
|
|
71
|
-
@multiply(2)
|
|
72
|
-
def four():
|
|
73
|
-
return 1
|
|
74
|
-
|
|
75
|
-
assrt.equal(2, two())
|
|
76
|
-
assrt.equal(3, three())
|
|
77
|
-
assrt.equal(4, four())
|
|
1
|
+
# vim:fileencoding=utf-8
|
|
2
|
+
# License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
+
|
|
4
|
+
def double(f):
|
|
5
|
+
return def (x):
|
|
6
|
+
return 2 * f(x)
|
|
7
|
+
|
|
8
|
+
def triple(f):
|
|
9
|
+
return def(x):
|
|
10
|
+
return 3 * f(x)
|
|
11
|
+
|
|
12
|
+
@double
|
|
13
|
+
def half(x):
|
|
14
|
+
return x // 2
|
|
15
|
+
|
|
16
|
+
@double
|
|
17
|
+
def f1(x):
|
|
18
|
+
return x
|
|
19
|
+
|
|
20
|
+
@double
|
|
21
|
+
@triple
|
|
22
|
+
def f2(x):
|
|
23
|
+
return x
|
|
24
|
+
|
|
25
|
+
def append_one(f):
|
|
26
|
+
return def(x):
|
|
27
|
+
ans = f(x)
|
|
28
|
+
ans.push(1)
|
|
29
|
+
return ans
|
|
30
|
+
|
|
31
|
+
def append_two(f):
|
|
32
|
+
return def(x):
|
|
33
|
+
ans = f(x)
|
|
34
|
+
ans.push(2)
|
|
35
|
+
return ans
|
|
36
|
+
|
|
37
|
+
@append_two
|
|
38
|
+
@append_one
|
|
39
|
+
def f3():
|
|
40
|
+
return []
|
|
41
|
+
|
|
42
|
+
o = {'double':double}
|
|
43
|
+
|
|
44
|
+
@o.double
|
|
45
|
+
def f4():
|
|
46
|
+
return 1
|
|
47
|
+
|
|
48
|
+
assrt.equal(2, half(2))
|
|
49
|
+
assrt.equal(4, f1(2))
|
|
50
|
+
assrt.equal(12, f2(2))
|
|
51
|
+
assrt.equal(2, f4())
|
|
52
|
+
assrt.deepEqual([1, 2], f3())
|
|
53
|
+
|
|
54
|
+
def multiply(amt):
|
|
55
|
+
|
|
56
|
+
def wrapper(f):
|
|
57
|
+
return def ():
|
|
58
|
+
return amt * f()
|
|
59
|
+
|
|
60
|
+
return wrapper
|
|
61
|
+
|
|
62
|
+
@multiply(2)
|
|
63
|
+
def two():
|
|
64
|
+
return 1
|
|
65
|
+
|
|
66
|
+
@multiply(3)
|
|
67
|
+
def three():
|
|
68
|
+
return 1
|
|
69
|
+
|
|
70
|
+
@multiply(2)
|
|
71
|
+
@multiply(2)
|
|
72
|
+
def four():
|
|
73
|
+
return 1
|
|
74
|
+
|
|
75
|
+
assrt.equal(2, two())
|
|
76
|
+
assrt.equal(3, three())
|
|
77
|
+
assrt.equal(4, four())
|
package/test/docstrings.pyj
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
# vim:fileencoding=utf-8
|
|
2
|
-
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
-
# globals: ρσ_module_doc__
|
|
4
|
-
|
|
5
|
-
import _import_one
|
|
6
|
-
|
|
7
|
-
def f():
|
|
8
|
-
" A basic docstring "
|
|
9
|
-
pass
|
|
10
|
-
|
|
11
|
-
assrt.equal(f.__doc__, 'A basic docstring')
|
|
12
|
-
assrt.equal(_import_one.__doc__, 'Module level ds1\n\nModule level ds2\nline2\n\nModule level ds 3')
|
|
13
|
-
|
|
14
|
-
def g():
|
|
15
|
-
'''
|
|
16
|
-
A more complex docstring:
|
|
17
|
-
xxx
|
|
18
|
-
yyyy
|
|
19
|
-
|
|
20
|
-
the end
|
|
21
|
-
'''
|
|
22
|
-
pass
|
|
23
|
-
|
|
24
|
-
assrt.equal(g.__doc__, 'A more complex docstring:\n xxx\n yyyy\n\nthe end')
|
|
25
|
-
|
|
26
|
-
class D:
|
|
27
|
-
' Docstring for a class '
|
|
28
|
-
|
|
29
|
-
def method(self):
|
|
30
|
-
'ds for a method'
|
|
31
|
-
pass
|
|
32
|
-
|
|
33
|
-
assrt.equal(D().__doc__, 'Docstring for a class')
|
|
34
|
-
assrt.equal(D().method.__doc__, 'ds for a method')
|
|
35
|
-
|
|
36
|
-
x = def():
|
|
37
|
-
'xxx'
|
|
38
|
-
|
|
39
|
-
assrt.equal(x.__doc__, 'xxx')
|
|
1
|
+
# vim:fileencoding=utf-8
|
|
2
|
+
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
+
# globals: ρσ_module_doc__
|
|
4
|
+
|
|
5
|
+
import _import_one
|
|
6
|
+
|
|
7
|
+
def f():
|
|
8
|
+
" A basic docstring "
|
|
9
|
+
pass
|
|
10
|
+
|
|
11
|
+
assrt.equal(f.__doc__, 'A basic docstring')
|
|
12
|
+
assrt.equal(_import_one.__doc__, 'Module level ds1\n\nModule level ds2\nline2\n\nModule level ds 3')
|
|
13
|
+
|
|
14
|
+
def g():
|
|
15
|
+
'''
|
|
16
|
+
A more complex docstring:
|
|
17
|
+
xxx
|
|
18
|
+
yyyy
|
|
19
|
+
|
|
20
|
+
the end
|
|
21
|
+
'''
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
assrt.equal(g.__doc__, 'A more complex docstring:\n xxx\n yyyy\n\nthe end')
|
|
25
|
+
|
|
26
|
+
class D:
|
|
27
|
+
' Docstring for a class '
|
|
28
|
+
|
|
29
|
+
def method(self):
|
|
30
|
+
'ds for a method'
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
assrt.equal(D().__doc__, 'Docstring for a class')
|
|
34
|
+
assrt.equal(D().method.__doc__, 'ds for a method')
|
|
35
|
+
|
|
36
|
+
x = def():
|
|
37
|
+
'xxx'
|
|
38
|
+
|
|
39
|
+
assrt.equal(x.__doc__, 'xxx')
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
# vim:fileencoding=utf-8
|
|
2
|
-
# License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
-
# globals: assrt
|
|
4
|
-
|
|
5
|
-
from elementmaker import E
|
|
6
|
-
|
|
7
|
-
eq = assrt.equal
|
|
8
|
-
|
|
9
|
-
def dummy_elem_eq(a, b):
|
|
10
|
-
eq(jstype(a), jstype(b))
|
|
11
|
-
if (jstype(a) == 'string'):
|
|
12
|
-
eq(a, b)
|
|
13
|
-
return
|
|
14
|
-
eq(a.attributes.length, b.attributes.length)
|
|
15
|
-
eq(a.children.length, b.children.length)
|
|
16
|
-
eq(a.name, b.name)
|
|
17
|
-
for attr in a.attributes:
|
|
18
|
-
eq(a[attr], b[attr])
|
|
19
|
-
for i, child in enumerate(a.children):
|
|
20
|
-
dummy_elem_eq(child, b.children[i])
|
|
21
|
-
|
|
22
|
-
q = E.div('text', id='1', class_='c', data_x='x')
|
|
23
|
-
dummy_elem_eq(q, {'name':'div', 'children':['text'], 'attributes':{'id':'1', 'class':'c', 'data-x': 'x'}})
|
|
24
|
-
|
|
25
|
-
q = E.div(
|
|
26
|
-
E.span('a'),
|
|
27
|
-
E.span('b'),
|
|
28
|
-
E.a(),
|
|
29
|
-
id='1',
|
|
30
|
-
boolean_attr=True,
|
|
31
|
-
)
|
|
32
|
-
dummy_elem_eq(q, {'name':'div', 'children':[
|
|
33
|
-
{
|
|
34
|
-
'name':'span',
|
|
35
|
-
'children':['a'], 'attributes': {}
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
'name':'span',
|
|
39
|
-
'children':['b'], 'attributes': {}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
'name':'a',
|
|
43
|
-
'children':[], 'attributes': {}
|
|
44
|
-
},
|
|
45
|
-
], 'attributes':{'id':'1', 'boolean-attr':'boolean-attr'}})
|
|
1
|
+
# vim:fileencoding=utf-8
|
|
2
|
+
# License: BSD Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
|
3
|
+
# globals: assrt
|
|
4
|
+
|
|
5
|
+
from elementmaker import E
|
|
6
|
+
|
|
7
|
+
eq = assrt.equal
|
|
8
|
+
|
|
9
|
+
def dummy_elem_eq(a, b):
|
|
10
|
+
eq(jstype(a), jstype(b))
|
|
11
|
+
if (jstype(a) == 'string'):
|
|
12
|
+
eq(a, b)
|
|
13
|
+
return
|
|
14
|
+
eq(a.attributes.length, b.attributes.length)
|
|
15
|
+
eq(a.children.length, b.children.length)
|
|
16
|
+
eq(a.name, b.name)
|
|
17
|
+
for attr in a.attributes:
|
|
18
|
+
eq(a[attr], b[attr])
|
|
19
|
+
for i, child in enumerate(a.children):
|
|
20
|
+
dummy_elem_eq(child, b.children[i])
|
|
21
|
+
|
|
22
|
+
q = E.div('text', id='1', class_='c', data_x='x')
|
|
23
|
+
dummy_elem_eq(q, {'name':'div', 'children':['text'], 'attributes':{'id':'1', 'class':'c', 'data-x': 'x'}})
|
|
24
|
+
|
|
25
|
+
q = E.div(
|
|
26
|
+
E.span('a'),
|
|
27
|
+
E.span('b'),
|
|
28
|
+
E.a(),
|
|
29
|
+
id='1',
|
|
30
|
+
boolean_attr=True,
|
|
31
|
+
)
|
|
32
|
+
dummy_elem_eq(q, {'name':'div', 'children':[
|
|
33
|
+
{
|
|
34
|
+
'name':'span',
|
|
35
|
+
'children':['a'], 'attributes': {}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
'name':'span',
|
|
39
|
+
'children':['b'], 'attributes': {}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
'name':'a',
|
|
43
|
+
'children':[], 'attributes': {}
|
|
44
|
+
},
|
|
45
|
+
], 'attributes':{'id':'1', 'boolean-attr':'boolean-attr'}})
|