python2rust 0.1.0__py3-none-any.whl

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 (102) hide show
  1. python2rust/__init__.py +8 -0
  2. python2rust/__main__.py +5 -0
  3. python2rust/_core.py +44 -0
  4. python2rust/agent/__init__.py +0 -0
  5. python2rust/agent/agents.py +333 -0
  6. python2rust/agent/apply.py +516 -0
  7. python2rust/agent/finish.py +295 -0
  8. python2rust/agent/fixers.py +229 -0
  9. python2rust/agent/loop.py +441 -0
  10. python2rust/agent/patches.py +1165 -0
  11. python2rust/agent/port.py +579 -0
  12. python2rust/agent/prompts/judge_v2.md +96 -0
  13. python2rust/agent/review.py +34 -0
  14. python2rust/agent/rustlex.py +232 -0
  15. python2rust/cli/__init__.py +0 -0
  16. python2rust/cli/doctor.py +62 -0
  17. python2rust/cli/inputs.py +105 -0
  18. python2rust/cli/main.py +1162 -0
  19. python2rust/cli/ops.py +642 -0
  20. python2rust/cli/workflow.py +178 -0
  21. python2rust/core/__init__.py +38 -0
  22. python2rust/core/config.py +263 -0
  23. python2rust/core/constructs.py +124 -0
  24. python2rust/core/diagnostics.py +280 -0
  25. python2rust/core/emit/__init__.py +5 -0
  26. python2rust/core/emit/crates.py +51 -0
  27. python2rust/core/emit/render.py +561 -0
  28. python2rust/core/emit/schema.py +168 -0
  29. python2rust/core/emit/translate.py +304 -0
  30. python2rust/core/frontend/__init__.py +1 -0
  31. python2rust/core/frontend/module.py +896 -0
  32. python2rust/core/frontend/names.py +129 -0
  33. python2rust/core/frontend/project.py +277 -0
  34. python2rust/core/frontend/project_imports.py +173 -0
  35. python2rust/core/frontend/symbols.py +132 -0
  36. python2rust/core/frontend/walrus.py +59 -0
  37. python2rust/core/ir/__init__.py +1 -0
  38. python2rust/core/ir/nodes.py +675 -0
  39. python2rust/core/ir/rtypes.py +122 -0
  40. python2rust/core/ir/types.py +326 -0
  41. python2rust/core/lower/__init__.py +1 -0
  42. python2rust/core/lower/calls.py +1125 -0
  43. python2rust/core/lower/context.py +223 -0
  44. python2rust/core/lower/exceptions.py +317 -0
  45. python2rust/core/lower/exprs.py +845 -0
  46. python2rust/core/lower/fstrings.py +141 -0
  47. python2rust/core/lower/funcs.py +276 -0
  48. python2rust/core/lower/lowerer.py +366 -0
  49. python2rust/core/lower/modelcalls.py +195 -0
  50. python2rust/core/lower/models.py +645 -0
  51. python2rust/core/lower/stmts.py +722 -0
  52. python2rust/core/lower/testing.py +601 -0
  53. python2rust/core/lower/validation.py +253 -0
  54. python2rust/core/passes/__init__.py +1 -0
  55. python2rust/core/passes/aliasing.py +311 -0
  56. python2rust/core/passes/analysis.py +207 -0
  57. python2rust/core/passes/devirt.py +329 -0
  58. python2rust/core/passes/ownership.py +259 -0
  59. python2rust/core/passes/raises.py +275 -0
  60. python2rust/core/rt_lib.rs +2071 -0
  61. python2rust/data/README.md +81 -0
  62. python2rust/data/py2many_builtins.toml +4744 -0
  63. python2rust/errors.py +28 -0
  64. python2rust/py.typed +0 -0
  65. python2rust/report/__init__.py +0 -0
  66. python2rust/report/constructs.py +31 -0
  67. python2rust/report/contract.py +688 -0
  68. python2rust/report/corpus.py +323 -0
  69. python2rust/report/explain.py +168 -0
  70. python2rust/report/schemas.py +914 -0
  71. python2rust/server/__init__.py +0 -0
  72. python2rust/server/mcp_server.py +289 -0
  73. python2rust/server/mcp_workflow.py +100 -0
  74. python2rust/skill/SKILL.md +214 -0
  75. python2rust/verify/__init__.py +0 -0
  76. python2rust/verify/check.py +1135 -0
  77. python2rust/verify/equiv/__init__.py +1264 -0
  78. python2rust/verify/equiv/compare.py +455 -0
  79. python2rust/verify/equiv/harness.py +505 -0
  80. python2rust/verify/equiv/judge.py +358 -0
  81. python2rust/verify/equiv/procs.py +255 -0
  82. python2rust/verify/equiv/runner.py +248 -0
  83. python2rust/verify/equiv/types.py +543 -0
  84. python2rust/verify/keystore.py +76 -0
  85. python2rust/verify/ladder.py +396 -0
  86. python2rust/verify/sandbox.py +370 -0
  87. python2rust/verify/testrun.py +280 -0
  88. python2rust/workflow/__init__.py +0 -0
  89. python2rust/workflow/brief.py +312 -0
  90. python2rust/workflow/interview.py +366 -0
  91. python2rust/workflow/layout.py +103 -0
  92. python2rust/workflow/planner.py +409 -0
  93. python2rust/workflow/project.py +134 -0
  94. python2rust/workflow/schemas.py +265 -0
  95. python2rust/workflow/state.py +392 -0
  96. python2rust/workflow/staticscan.py +209 -0
  97. python2rust-0.1.0.dist-info/METADATA +395 -0
  98. python2rust-0.1.0.dist-info/RECORD +102 -0
  99. python2rust-0.1.0.dist-info/WHEEL +4 -0
  100. python2rust-0.1.0.dist-info/entry_points.txt +4 -0
  101. python2rust-0.1.0.dist-info/licenses/LICENSE +21 -0
  102. python2rust-0.1.0.dist-info/licenses/NOTICE +65 -0
@@ -0,0 +1,81 @@
1
+ # python2rust data files
2
+
3
+ ## py2many_builtins.toml
4
+
5
+ A table that maps Python builtins, methods, operators, subscripts, format specs and
6
+ types to Rust, mined from [py2many](https://github.com/py2many/py2many) 0.9 (MIT, see
7
+ `NOTICE`) and reviewed against Python semantics. It is generated, not hand-edited:
8
+
9
+ python3 tools/mine_py2many.py PATH/TO/py2many-X.Y
10
+
11
+ The script parses py2many's Rust tables with `ast` (it never imports py2many), merges
12
+ them with the curated review kept in the script, and writes this file. A py2many key
13
+ the review does not claim is written as `status = "unreviewed"`, so mining a newer
14
+ py2many shows up as a reviewable diff. It also checks that every Rust template parses
15
+ (rustfmt) and that `NOTICE` still holds py2many's license text.
16
+
17
+ ### Entry schema
18
+
19
+ [[builtin]]
20
+ python = "str.split" # name; methods are "type.method", operators are the symbol
21
+ kind = "method" # function | method | operator | constant | type | format
22
+ # | subscript | subscript-assign | slice | statement | syntax | attribute
23
+ types = ["str"] # argument/receiver types this overload applies to (optional)
24
+ arity = "0" # "1", "2", "3+", "1+key", "2 (range-proven)" ... free text (optional)
25
+ rust = "$self.split_whitespace().collect::<Vec<&str>>()"
26
+ status = "direct" # see below
27
+ helper = "" # runtime helper name, required when status = needs-runtime-helper
28
+ imports = ["std::collections::HashSet"] # `use` paths the template needs (optional)
29
+ crates = ["indexmap"] # crates the template needs (optional)
30
+ min_rust = "1.77" # minimum Rust version, if relevant (optional)
31
+ origin = "py2many" # py2many = a py2many table has this key; original = it does not
32
+ source = "pyrs/transpiler.py:_STR_METHODS + _visit_str_method['split']"
33
+ py2many_emits = "..." # what py2many emits, for comparison (optional)
34
+ notes = "..." # caveats; "ERROR-GAP:" marks Python-raises vs Rust-returns-nan/inf
35
+
36
+ The same `python` name appears several times when the Rust differs by argument type or
37
+ arity. Select by `(python, types, arity)`.
38
+
39
+ Placeholders in `rust`: `$0`..`$9` positional arguments, `$self` the receiver, `$args`
40
+ all arguments comma-joined, `$T` the element type, any other `$name` a keyword argument
41
+ or a generated name. `$` avoids a clash with Rust format-string braces.
42
+
43
+ ### Status values
44
+
45
+ | status | meaning |
46
+ |---|---|
47
+ | `direct` | faithful for the stated types; any remaining edge cases are in `notes` |
48
+ | `corrected` | py2many has a mapping, but it is wrong or lossy; `rust` is the replacement and `py2many_emits` shows the original |
49
+ | `needs-runtime-helper` | no faithful inline Rust exists (floor division, `%`, `round`, `str` length, slicing, float `str`, ...). `rust` calls `p2r::<helper>`; the helper is described in a `[[helper]]` table |
50
+ | `compile-time` | resolved while transpiling (for example `isinstance` on a statically known type) |
51
+ | `unsupported` | reject loudly; py2many's output is not usable |
52
+ | `unreviewed` | present in the mined py2many version, not yet reviewed |
53
+
54
+ ### Policies baked into the table
55
+
56
+ - Python `int` maps to `i64` (py2many uses `i32`, which silently truncates). Arithmetic that
57
+ can overflow is `needs-runtime-helper` (checked), with a plain-operator variant marked
58
+ `range-proven` for use when range analysis shows no overflow.
59
+ - `dict` maps to `indexmap::IndexMap` (insertion order, as Python), not `HashMap`.
60
+ - `p2r` is a placeholder name for a runtime helper crate. No such crate exists yet; the
61
+ `[[helper]]` entries are its proposed signatures and semantics.
62
+ - Every template is syntax-checked by the mining script (rustfmt). Templates that do not
63
+ use `p2r::` helpers were additionally compiled by hand against sample values (rustc
64
+ 1.100) for the common cases, but there is no compile gate in the script yet: helpers
65
+ and generic types referenced by the others do not exist. Claims marked "verified" in
66
+ `notes` were checked with rustc 1.100 and CPython 3.15 while mining.
67
+ - Entries with `origin = "original"` are our own recommendation, not derived from py2many.
68
+
69
+ ### Other tables in the file
70
+
71
+ - `[keywords]`: Rust reserved words, the subset that can collide with Python identifiers,
72
+ the ones py2many escapes, and the ones it misses (`let`, `mod`, `self`, `static`,
73
+ `crate`, ...). `crate`, `self`, `Self`, `super` cannot use `r#` raw identifiers.
74
+ - `[width_rank]`: py2many's numeric widening order. Reference only.
75
+ - `[status_values]`, `[meta]`: legend and mining metadata.
76
+
77
+ ## Test inputs
78
+
79
+ `tests/data/py2many_cases/` holds py2many's own test programs and its expected Rust,
80
+ with a `manifest.json` describing each (constructs used, whether it fits P0/P1, whether
81
+ the reference Rust parses). See `docs/FROM_PY2MANY.md`.