@cella-lang/python 0.1.202611101336 → 0.1.202611132107
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/CHANGES.md +51 -0
- package/README.md +8 -3
- package/index.json +2297 -2157
- package/package.json +6 -6
- package/python.builtins.cell +0 -0
- package/python.calls.cell +0 -0
- package/python.cell +0 -0
- package/python.containers.cell +0 -0
- package/python.debugging.cell +0 -0
- package/python.dispatch.cell +0 -0
- package/python.execution.cell +0 -0
- package/python.flattening.cell +0 -0
- package/python.generators.cell +0 -0
- package/python.iterators.cell +0 -0
- package/python.lazy.cell +0 -0
- package/python.lowering.cell +0 -0
- package/python.methods.cell +0 -0
- package/python.numbers.cell +0 -0
- package/python.objects.cell +0 -0
- package/python.operations.cell +0 -0
- package/python.printing.cell +0 -0
- package/python.querying.cell +0 -0
- package/python.random.cell +0 -0
- package/python.session.cell +0 -0
- package/python.sets.cell +0 -0
- package/python.sorting.cell +0 -0
- package/python.symbols.cell +0 -0
- package/python.syntax.cell +0 -0
- package/python.text.cell +0 -0
- package/python.values.cell +0 -0
- package/python.variables.cell +0 -0
package/CHANGES.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
## 未發佈
|
|
4
4
|
|
|
5
|
+
- **新增 slice 物件**(之前 `slice(...)` 判 unknown,`xs[a:b]` 只在內部讀界限):`slice(stop)`、`slice(start, stop[, step])`
|
|
6
|
+
(參數個數與 keyword 的 TypeError 照 CPython),repr 與 str 是 `slice(1, 2, None)`,`start`、`stop`、`step` 是給的值
|
|
7
|
+
(唯讀:設定或刪除是 `AttributeError: readonly attribute`),`type(s) is slice`、`isinstance`。`indices(n)` 照
|
|
8
|
+
`slice_indices`:長度要是整數且不是負的、step 0 的 ValueError、界限不是整數或 None 的 TypeError,再照
|
|
9
|
+
`_PySlice_GetLongIndices` 截到長度(任意大的整數)。`==` 與 `<` 等照 (start, stop, step) 這個 tuple 比較(和 tuple
|
|
10
|
+
比是 TypeError);hash 照 3.12 起的 `slice_hash`,可以當 dict 的 key 與 set 的元素,部分不能 hash 時是
|
|
11
|
+
`cannot use 'slice' as a dict key (unhashable type: 'list')`。不能下標、沒有 len、不能迭代、不能當基底類別(bool、
|
|
12
|
+
range 也是:`type 'bool' is not an acceptable base type`,之前錯判 accept)。切片語法 `c[a:b:k]` 就是以 slice 物件當
|
|
13
|
+
下標,`c[slice(a, b, k)]` 一樣:dict 照 key 查(找到就取值;KeyError 的 `args[0]` 是 slice 物件,之前用
|
|
14
|
+
`except ... as e` 接住是 unknown),使用者的 `__getitem__`、`__setitem__`、`__delitem__` 收到 slice 物件(之前
|
|
15
|
+
unknown),`del xs[a:b:k]`、`xs[a:b] += ys`、`d[a:b] = v`、`del d[a:b]` 都支援(之前 unknown);含使用者物件的切片
|
|
16
|
+
當 dict 的 key 照一般的 key(KeyError 印出物件時記 `object.address`)。
|
|
17
|
+
- 修正:讀一個程式與內建都沒有定義的名字是 `NameError: name 'x' is not defined`(之前在函式、lambda、類別的方法裡讀
|
|
18
|
+
它錯判 accept:把它當成一個同名的內建類別,`def g(): return undefined_name` 印出 `<class 'undefined_name'>`;模組最上層
|
|
19
|
+
照舊)。只在真的讀到時才丟(沒走到的分支不算);呼叫一個沒有定義的名字在算參數之前就丟(CPython 先讀被呼叫的名字)。
|
|
20
|
+
`global`、`nonlocal`、閉包、類別的方法都照 CPython 的範圍規則。`__build_class__`、`__debug__`、`__import__` 這幾個
|
|
21
|
+
模型不提供的內建名字判 unknown。
|
|
22
|
+
- **使用者的函式有身分**:每次跑 `def`、`lambda` 都做一個新的函式物件(放在 heap 上,和物件一樣有位址)。函式當 dict
|
|
23
|
+
的 key、set 的元素,`==`、`is`、`in`、`list.index`、`list.count` 都照身分(之前 `{add: '+'}`、`f in {f}`、`f == f`
|
|
24
|
+
是 unknown);綁定的方法照它綁的物件與函式比較、可以當 key;內建函式照名字。印出使用者的函式顯示它的位址
|
|
25
|
+
(`<function f at 0x1000>`,assumes 記 `object.address`;之前是 unknown);除錯器的變數檢視也一樣(之前是
|
|
26
|
+
`<function f>`)。只有函式的 set 照位址排序(同樣記 `object.address`)。兩個綁定的方法用 `is` 比較、綁定的方法的
|
|
27
|
+
set(兩個以上的元素)、綁在不是物件的值上的方法當 key 仍是 unknown。注意:類別裡的每個 `def` 現在也佔一個 heap
|
|
28
|
+
位置,之後建立的物件的位址往後移。
|
|
29
|
+
- **新增切片指定 `xs[a:b] = ys`、`xs[a:b:k] = ys`**(之前判 unknown:`a slice outside a subscript`):照 CPython 的
|
|
30
|
+
`list_ass_subscript`——step 是 1(或省略)時取代那一段,長度可以不同(`a[1:3] = [9]`、`a[3:1] = …` 插在 3);step 不是 1 時
|
|
31
|
+
長度要相同,否則 `ValueError: attempt to assign sequence of size X to extended slice of size Y`(負的 step 照樣)。右邊是任何
|
|
32
|
+
iterable(str、tuple、range、dict、自己、generator;generator 在界限讀完之後才取,界限錯了不取),不是 iterable 是
|
|
33
|
+
`TypeError: must assign iterable to extended slice`;界限的 TypeError、step 0 的 ValueError 照 `PySlice_Unpack` 的順序;
|
|
34
|
+
tuple、str、沒有 `__setitem__` 的物件是 `does not support item assignment`。`for xs[0:2] in …` 的目標也是。
|
|
35
|
+
- 修正:模型丟出的內建例外帶著原本的參數。`except KeyError as e` 的 `e.args[0]` 是 key 本身(之前是 key 的 repr 字串:
|
|
36
|
+
`d['b']` 的 `e.args[0]` 是 `"'b'"`、`d[5]` 的是 `'5'`),`str(e)` 是 key 的 repr、`repr(e)` 是 `KeyError(5)`;下標、`del`、
|
|
37
|
+
`dict.pop`、`set.remove`、`str.format` 的 keyword 都是。`assert x, msg` 的 AssertionError 的 `args` 是 `(msg,)` 原本的值
|
|
38
|
+
(之前是它的 str),`str(e)` 照舊。其他內建例外的 `args` 照舊是訊息。重新丟出接住的內建例外,訊息照它的參數算。
|
|
39
|
+
- 修正:hash 與身分照 CPython 3.14。`__hash__ = None` 的類別的物件不能當 dict 的 key 或 set 的元素(之前錯判 accept:
|
|
40
|
+
`{H(): 1}`;放進 set 之前是 unknown);不能 hash 的訊息點名最內層的型別(`{(1, [2]): 3}` 是
|
|
41
|
+
`cannot use 'tuple' as a dict key (unhashable type: 'list')`)。generator、iterator、dict 的 values view 可以當 key(之前錯判
|
|
42
|
+
TypeError),keys/items view 不行。內建函式彼此比較與當 key 照它的名字(之前 `len == len` 是 False、`{len: 1}[len]` 是
|
|
43
|
+
KeyError);`NotImplemented == NotImplemented` 是 True。使用者的函式與綁定的方法當 key、set 的元素,或和一樣的函式比較
|
|
44
|
+
(`f == f`、`f in [f]`)是 unknown:CPython 照物件的身分,模型的函式值沒有身分(之前錯判 False 或 KeyError);不同的函式
|
|
45
|
+
比較照舊是 False。兩個以上的元素、其中有模型不給 hash 的(range、類別、內建函式、NaN)的 set 是 unknown:CPython 的順序
|
|
46
|
+
跟著 hash(多半是位址),之前照加入的順序印是猜的。
|
|
47
|
+
- 修正:切片取值照 CPython 的 `PySlice_Unpack` 讀界限(先 step,再 start、stop):不是整數(bool 算整數)或 None 的界限是
|
|
48
|
+
`TypeError: slice indices must be integers or None or have an __index__ method`(之前當成省略:`[1, 2, 3]['x':2]`、
|
|
49
|
+
`a[1.5:2]`、`'abc'[None:'q']` 錯判 accept),step 0 的 `ValueError` 在界限的錯誤之前。`range` 的切片是 range
|
|
50
|
+
(`range(10)[::-1]` 是 `range(9, -1, -1)`;之前錯判 `'range' object is not subscriptable`)。dict 的切片取值照 3.14:
|
|
51
|
+
`KeyError: slice(1, 2, None)`,部分不能 hash 是 `TypeError: cannot use 'slice' as a dict key (unhashable type: 'list')`
|
|
52
|
+
(之前是 not subscriptable)。
|
|
53
|
+
- **新增 `math.isqrt`**(之前判 unknown):任意大的整數的整數平方根;負數是 `ValueError: isqrt() argument must be nonnegative`,
|
|
54
|
+
不是整數是 `TypeError`(bool 算整數),參數個數與關鍵字的錯誤同 `math.factorial`。精確,不附假設。
|
|
5
55
|
- **新增 `math.fmod`**(之前判 unknown):照 CPython 的 `math_fmod`——結果帶被除數的符號,除數是 0 或被除數無限(除數有限)是
|
|
6
56
|
`ValueError: math domain error`,無限的除數給被除數,NaN 傳下去,參數個數與型別的錯誤同 `math.pow`。對 CPython 的差分
|
|
7
57
|
(`tools/diff.py --only-math`,fmod 與 pow 的數值格子)全一致。fmod 是精確的,不附假設。
|
|
@@ -29,6 +79,7 @@
|
|
|
29
79
|
`termination`(未接住的例外)、`incomplete`(程式有洞)、`invalid`(程式的 JSON 不合法)。
|
|
30
80
|
### ⚠️ 不相容
|
|
31
81
|
|
|
82
|
+
- `python.Lazy.at` 改名為 `python.Lazy.slot`(意思不變:第 k 個保留的區域變數的位置)。`at` 在新語法裡是成員的名字。
|
|
32
83
|
- 判決的每個問題多兩欄:`params` 與 `structured`(和 C 家族同一個形狀)。未接住的例外帶 `at`(拋出的節點,知道時)。
|
|
33
84
|
NameError 的 kind 從 `uncaught` 改成 `undeclared`,params 是 `name` 與 `what: "name"`;category 照舊 `termination`、判決照舊 accept、
|
|
34
85
|
exit 1、reason 照舊是 CPython 的最後一行。dist 附 `verdict-kinds.json`。
|
package/README.md
CHANGED
|
@@ -18,7 +18,8 @@ Depends on `@cella-lang/machine`.
|
|
|
18
18
|
not a program). `assumes` (always there) lists the implementation's choices the run relied on, each
|
|
19
19
|
`{"implementation": "CPython", "choice": …}`: `random.seed` (an unseeded `random` starts as
|
|
20
20
|
`seed(0)`), `str.hash` (a set ordered by str hashes, as under `PYTHONHASHSEED=0`) and `object.address` (an object's
|
|
21
|
-
address shown as text, or a set ordered by objects' hashes
|
|
21
|
+
address shown as text, or a set ordered by objects' hashes; each run of a `def` or `lambda` makes a function object
|
|
22
|
+
of its own, so a user's function is one too: the model places the object at heap position `a` at
|
|
22
23
|
`0x1000 + 16a`, not where CPython's memory would). A verdict proved by the kernels:
|
|
23
24
|
`kernel_verdict_in("python", "python.verdict", …)` in `cella-lang`.
|
|
24
25
|
- `python.types json candidates`: the type query, in the same shape as the C family's: `nodes` (the type of each
|
|
@@ -81,8 +82,12 @@ and `math.fmod` are exact and assume nothing.
|
|
|
81
82
|
## Not in this version
|
|
82
83
|
|
|
83
84
|
Modules other than `math` and `random`, the `!a` conversion, built-ins the model does not provide (`hex` and others),
|
|
84
|
-
a user's object compared inside a container comparison,
|
|
85
|
-
|
|
85
|
+
a user's object compared inside a container comparison, a NaN or a method bound to a value that is not an object
|
|
86
|
+
as a dict key or set element or compared with one alike (CPython goes by its identity, which the model's value does not
|
|
87
|
+
keep), `is` between two bound methods (CPython makes a new one each time it reads the attribute), a set of two or
|
|
88
|
+
more items one of which has a hash the model does not give (a range, a built-in class or function, a bound method,
|
|
89
|
+
NaN: CPython's order follows the hash), a slice whose bounds are a user's object with `__index__`, and assigning to a
|
|
90
|
+
list's slice from an iterable that runs a user's code anywhere but `xs[a:b] = v` itself. A program that uses one of them is `unknown` with the construct
|
|
86
91
|
named (`tests/deep_unsupported`).
|
|
87
92
|
|
|
88
93
|
## Loading
|