@cella-lang/python

中文文档
0.1.202611091000发布于 2026/11/09Apache-2.0零依赖近 30 天下载 1.1万

A Python model for Cella Lang: dynamically typed values (arbitrary-precision int, IEEE 754 float, str, tuple, list, dict, set on a heap), operations and printing that match CPython exactly, exceptions, and statements on @cella-lang/machine's small-step ma

原始使用文档
文档目录5 节
  1. Entries
  2. Modules
  3. Assumed
  4. Not in this version
  5. Loading

@cella-lang/python

Python for the Cella proof checker, as a compiled module pack. A program comes as its syntax tree (a subset of CPython's ast as JSON); the model runs it with CPython 3.14's semantics and gives a verdict, a debugger that stops where CPython's tracer does, and a type query for the editor. Everything is defined in Cella, so a verdict can be proved by both kernels.

Depends on @cella-lang/machine.

Entries

  • python.verdict json input fuel: runs the program on the input for at most fuel steps and returns {verdict, basis, exit, out, problems, assumes} (the same shape as the C family's verdicts). An uncaught exception is defined behavior (accept, exit 1, the exception as a problem). Running out of steps, a construct the model does not take (unsupported, naming it) and an empty slot of the editor (hole, at its label) are unknown, never a guess. Each problem has a category as the C family's do (termination for an uncaught exception, unsupported, incomplete for an empty slot, indeterminate for the step limit or waiting for input, invalid for JSON that is not a program). assumes (always there) lists the implementation's choices the run relied on, each {"implementation": "CPython", "choice": …}: random.seed (an unseeded random starts as seed(0)), str.hash (a set ordered by str hashes, as under PYTHONHASHSEED=0) and object.address (an object's address shown as text, or a set ordered by objects' hashes: the model places the object at heap position a at 0x1000 + 16a, not where CPython's memory would). A verdict proved by the kernels: kernel_verdict_in("python", "python.verdict", …) in cella-lang.
  • python.types json candidates: the type query, in the same shape as the C family's: nodes (the type of each expression whose type is known before the program runs, as type(x).__name__), slots (for each hole, each candidate type is exact, no with the reason, or unknown when it depends on values at run time) and errors (operations that raise TypeError whenever they run, with CPython's message, also in code that does not run). An operation is tried on a value of each operand's type with the model's own operations; there is no second set of typing rules.
  • python.observedTypes json input fuel: the types one run saw, {verdict, nodes, basis}. nodes maps each expression's node (and each name an assignment, for or with binds, and each parameter) to its type as Python's typing writes it: int, float, str, bool, None, a class's name; list[int], set[str], dict[str, int] with the union of the items' (keys', values') types, tuple[int, str] by position; list[?], set[?], dict[?, ?], tuple[()] when empty. A node whose values had several types gets their union in the order first seen (int|str). basis says observed for those, and unreached (with the empty text) for a node the run did not reach. The types hold for this input only. A run the model cannot finish (unknown) or JSON that is not a program (invalid) gives empty nodes and basis.
  • python.session: the debugger, for cella-lang/dap: load, run (continue, step in, step over, step out, with breakpoints), stopConf, stopKind, stopNode, stopOut, stopErr, stopDetail, feed (more input), globals, frames, setVarErr, setVarConf, env, and lines when the host has the line of each node (statements on one line then stop once, as CPython's line event). A stop is at a node; an uncaught exception stops with {"type", "what", "node"}, the node being the expression that raised it.

Modules

Each module imports the standard library, @cella-lang/machine and the modules above it.

ModuleWhat it is
python.syntaxpython.ast.Program: a subset of CPython's ast with the same constructor and field names behind a prefix (e for expressions, s for statements) and a node id n on each; deriving Json gives the JSON form, literals are text; eHole is an empty slot
python.valuesvalues (None, bool, int of any size, float, str as code points, tuple, range, classes, functions) and the heap (list, dict, set, views, iterators, cells, instances, classes, generators), raised exceptions, type names and truth
python.numbersint and float, floor division and % toward negative infinity, exact comparison of int with float, bitwise operations as infinite two's complement, CPython's hashes
python.textstr as code points, the classes of code points the model knows, int(s) and float(s)
python.printingrepr and str (a float's shortest round-trip form)
python.containers, python.setslists, dicts in insertion order, sets in CPython's hash-table order
python.iteratorsiter, next, enumerate, zip, and the size checks of dict and set iterators
python.operationsthe operators on the built-in types, with CPython's errors
python.objectsattributes, classes (C3 method resolution order), descriptors, closures, exception classes
python.callsbinding arguments to parameters as CPython's initialize_locals, * and ** at a call
python.methods, python.builtinsthe methods of str, list, dict and set; the built-in functions and math
python.randomCPython's Mersenne Twister bit for bit, and Lib/random.py's functions
python.symbolsthe symbol table, as CPython's symtable
python.execution, python.generatorsrunning statements on machine.statement; generators and send, throw, close
python.dispatchthe user's special methods as statements (operators, comparisons, truth, len, iteration)
python.flattening, python.lazy, python.sortinga generator's body as a continuation; map, filter and the other lazy built-ins; sorting with the user's comparisons in CPython's order
python.loweringthe syntax tree as statements, and the verdict
python.debugging, python.variablesthe debugger's machine (stops as CPython's line events); variables, calls and globals as JSON
python.queryingthe type query; the types a run observed
python.sessionthe debugger's entry points
pythonthe entry: python.verdict, python.types, python.observedTypes

Assumed

A float's ** (and pow, math.pow, the math functions) gives the correctly rounded result. CPython calls the platform's C pow, which the C standard does not require to round correctly (macOS gives 1.7976931348623157e308 ** 0.5 one unit in the last place above the correctly rounded value); as for C and C++, a verdict that depends on the last bit holds for a libm that rounds correctly.

Not in this version

Modules other than math and random, the !a conversion, built-ins the model does not provide (hex and others), a user's object compared inside a container comparison, and a user's function shown as text (CPython shows its address; a function value of the model has none). A program that uses one of them is unknown with the construct named (tests/deep_unsupported).

Loading

Load the packs into the cella-lang build named by index.json (checkerHash, cbfVersion; the peerDependencies pin it): the standard modules in index.requires["cella-lang"].modules, the packages in index.requires.packages (each the same way), then this package's modules in the order of index.modules.python.deps. cella-lang's README (Official packages) has the code.

版本与发布记录

@cella-lang/python 共发布 61 个版本,首次发布于 2026/10/30;过去 12 个月发布了 61 个版本。

版本发布日期距今
0.1.202611091000latest2026/11/09今天
0.1.2026110909552026/11/09今天
0.1.2026110822142026/11/09今天
0.1.2026110809592026/11/081 天前
0.1.2026110805242026/11/081 天前
0.1.2026110804162026/11/081 天前

关于 @cella-lang/python 的常见问题

@cella-lang/python 是什么?

A Python model for Cella Lang: dynamically typed values (arbitrary-precision int, IEEE 754 float, str, tuple, list, dict, set on a heap), operations and printing that match CPython exactly, exceptions, and statements on @cella-lang/machine's small-step ma

如何安装 @cella-lang/python?

在项目目录运行 npm install @cella-lang/python,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:cella-lang(0.1.202611090954)、@cella-lang/machine(0.1.202611090959)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cella-lang/python 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cella-lang__python 是否存在。

@cella-lang/python 可以商用吗?

@cella-lang/python 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cella-lang/python 的下载量有多少?

根据 npm 官方下载统计,@cella-lang/python 在 2026/10/10 – 2026/11/08 这 30 天内被下载 10,937 次,日均约 365 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cella-lang/python 还在维护吗?

最新版本 0.1.202611091000 发布于 2026/11/09(今天);至今共发布 61 个版本,其中过去 12 个月发布了 61 个;首次发布于 2026/10/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。