python2rust 0.1.0__tar.gz
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.
- python2rust-0.1.0/AGENTS.md +127 -0
- python2rust-0.1.0/LICENSE +21 -0
- python2rust-0.1.0/NOTICE +65 -0
- python2rust-0.1.0/PKG-INFO +395 -0
- python2rust-0.1.0/README.md +360 -0
- python2rust-0.1.0/docs/AGENT_WORKFLOW.md +53 -0
- python2rust-0.1.0/docs/ARCHITECTURE.md +152 -0
- python2rust-0.1.0/docs/EQUIVALENCE.md +189 -0
- python2rust-0.1.0/docs/FROM_PY2MANY.md +278 -0
- python2rust-0.1.0/docs/WRONG_BUT_COMPILES.md +71 -0
- python2rust-0.1.0/docs/assets/logo.svg +1 -0
- python2rust-0.1.0/llms.txt +36 -0
- python2rust-0.1.0/pyproject.toml +108 -0
- python2rust-0.1.0/pyproject.toml.orig +82 -0
- python2rust-0.1.0/rt/Cargo.lock +278 -0
- python2rust-0.1.0/rt/Cargo.toml +26 -0
- python2rust-0.1.0/rt/src/lib.rs +9 -0
- python2rust-0.1.0/src/python2rust/__init__.py +8 -0
- python2rust-0.1.0/src/python2rust/__main__.py +5 -0
- python2rust-0.1.0/src/python2rust/_core.py +44 -0
- python2rust-0.1.0/src/python2rust/agent/__init__.py +0 -0
- python2rust-0.1.0/src/python2rust/agent/agents.py +333 -0
- python2rust-0.1.0/src/python2rust/agent/apply.py +516 -0
- python2rust-0.1.0/src/python2rust/agent/finish.py +295 -0
- python2rust-0.1.0/src/python2rust/agent/fixers.py +229 -0
- python2rust-0.1.0/src/python2rust/agent/loop.py +441 -0
- python2rust-0.1.0/src/python2rust/agent/patches.py +1165 -0
- python2rust-0.1.0/src/python2rust/agent/port.py +579 -0
- python2rust-0.1.0/src/python2rust/agent/prompts/judge_v2.md +96 -0
- python2rust-0.1.0/src/python2rust/agent/review.py +34 -0
- python2rust-0.1.0/src/python2rust/agent/rustlex.py +232 -0
- python2rust-0.1.0/src/python2rust/cli/__init__.py +0 -0
- python2rust-0.1.0/src/python2rust/cli/doctor.py +62 -0
- python2rust-0.1.0/src/python2rust/cli/inputs.py +105 -0
- python2rust-0.1.0/src/python2rust/cli/main.py +1162 -0
- python2rust-0.1.0/src/python2rust/cli/ops.py +642 -0
- python2rust-0.1.0/src/python2rust/cli/workflow.py +178 -0
- python2rust-0.1.0/src/python2rust/core/__init__.py +38 -0
- python2rust-0.1.0/src/python2rust/core/config.py +263 -0
- python2rust-0.1.0/src/python2rust/core/constructs.py +124 -0
- python2rust-0.1.0/src/python2rust/core/diagnostics.py +280 -0
- python2rust-0.1.0/src/python2rust/core/emit/__init__.py +5 -0
- python2rust-0.1.0/src/python2rust/core/emit/crates.py +51 -0
- python2rust-0.1.0/src/python2rust/core/emit/render.py +561 -0
- python2rust-0.1.0/src/python2rust/core/emit/schema.py +168 -0
- python2rust-0.1.0/src/python2rust/core/emit/translate.py +304 -0
- python2rust-0.1.0/src/python2rust/core/frontend/__init__.py +1 -0
- python2rust-0.1.0/src/python2rust/core/frontend/module.py +896 -0
- python2rust-0.1.0/src/python2rust/core/frontend/names.py +129 -0
- python2rust-0.1.0/src/python2rust/core/frontend/project.py +277 -0
- python2rust-0.1.0/src/python2rust/core/frontend/project_imports.py +173 -0
- python2rust-0.1.0/src/python2rust/core/frontend/symbols.py +132 -0
- python2rust-0.1.0/src/python2rust/core/frontend/walrus.py +59 -0
- python2rust-0.1.0/src/python2rust/core/ir/__init__.py +1 -0
- python2rust-0.1.0/src/python2rust/core/ir/nodes.py +675 -0
- python2rust-0.1.0/src/python2rust/core/ir/rtypes.py +122 -0
- python2rust-0.1.0/src/python2rust/core/ir/types.py +326 -0
- python2rust-0.1.0/src/python2rust/core/lower/__init__.py +1 -0
- python2rust-0.1.0/src/python2rust/core/lower/calls.py +1125 -0
- python2rust-0.1.0/src/python2rust/core/lower/context.py +223 -0
- python2rust-0.1.0/src/python2rust/core/lower/exceptions.py +317 -0
- python2rust-0.1.0/src/python2rust/core/lower/exprs.py +845 -0
- python2rust-0.1.0/src/python2rust/core/lower/fstrings.py +141 -0
- python2rust-0.1.0/src/python2rust/core/lower/funcs.py +276 -0
- python2rust-0.1.0/src/python2rust/core/lower/lowerer.py +366 -0
- python2rust-0.1.0/src/python2rust/core/lower/modelcalls.py +195 -0
- python2rust-0.1.0/src/python2rust/core/lower/models.py +645 -0
- python2rust-0.1.0/src/python2rust/core/lower/stmts.py +722 -0
- python2rust-0.1.0/src/python2rust/core/lower/testing.py +601 -0
- python2rust-0.1.0/src/python2rust/core/lower/validation.py +253 -0
- python2rust-0.1.0/src/python2rust/core/passes/__init__.py +1 -0
- python2rust-0.1.0/src/python2rust/core/passes/aliasing.py +311 -0
- python2rust-0.1.0/src/python2rust/core/passes/analysis.py +207 -0
- python2rust-0.1.0/src/python2rust/core/passes/devirt.py +329 -0
- python2rust-0.1.0/src/python2rust/core/passes/ownership.py +259 -0
- python2rust-0.1.0/src/python2rust/core/passes/raises.py +275 -0
- python2rust-0.1.0/src/python2rust/core/rt_lib.rs +2071 -0
- python2rust-0.1.0/src/python2rust/data/README.md +81 -0
- python2rust-0.1.0/src/python2rust/data/py2many_builtins.toml +4744 -0
- python2rust-0.1.0/src/python2rust/errors.py +28 -0
- python2rust-0.1.0/src/python2rust/py.typed +0 -0
- python2rust-0.1.0/src/python2rust/report/__init__.py +0 -0
- python2rust-0.1.0/src/python2rust/report/constructs.py +31 -0
- python2rust-0.1.0/src/python2rust/report/contract.py +688 -0
- python2rust-0.1.0/src/python2rust/report/corpus.py +323 -0
- python2rust-0.1.0/src/python2rust/report/explain.py +168 -0
- python2rust-0.1.0/src/python2rust/report/schemas.py +914 -0
- python2rust-0.1.0/src/python2rust/server/__init__.py +0 -0
- python2rust-0.1.0/src/python2rust/server/mcp_server.py +289 -0
- python2rust-0.1.0/src/python2rust/server/mcp_workflow.py +100 -0
- python2rust-0.1.0/src/python2rust/skill/SKILL.md +214 -0
- python2rust-0.1.0/src/python2rust/verify/__init__.py +0 -0
- python2rust-0.1.0/src/python2rust/verify/check.py +1135 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/__init__.py +1264 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/compare.py +455 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/harness.py +505 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/judge.py +358 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/procs.py +255 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/runner.py +248 -0
- python2rust-0.1.0/src/python2rust/verify/equiv/types.py +543 -0
- python2rust-0.1.0/src/python2rust/verify/keystore.py +76 -0
- python2rust-0.1.0/src/python2rust/verify/ladder.py +396 -0
- python2rust-0.1.0/src/python2rust/verify/sandbox.py +370 -0
- python2rust-0.1.0/src/python2rust/verify/testrun.py +280 -0
- python2rust-0.1.0/src/python2rust/workflow/__init__.py +0 -0
- python2rust-0.1.0/src/python2rust/workflow/brief.py +312 -0
- python2rust-0.1.0/src/python2rust/workflow/interview.py +366 -0
- python2rust-0.1.0/src/python2rust/workflow/layout.py +103 -0
- python2rust-0.1.0/src/python2rust/workflow/planner.py +409 -0
- python2rust-0.1.0/src/python2rust/workflow/project.py +134 -0
- python2rust-0.1.0/src/python2rust/workflow/schemas.py +265 -0
- python2rust-0.1.0/src/python2rust/workflow/state.py +392 -0
- python2rust-0.1.0/src/python2rust/workflow/staticscan.py +209 -0
- python2rust-0.1.0/tests/__init__.py +0 -0
- python2rust-0.1.0/tests/_stub_core.py +235 -0
- python2rust-0.1.0/tests/conftest.py +95 -0
- python2rust-0.1.0/tests/core/conftest.py +51 -0
- python2rust-0.1.0/tests/core/rustcheck.py +181 -0
- python2rust-0.1.0/tests/core/test_alias_generator.py +390 -0
- python2rust-0.1.0/tests/core/test_alias_patterns.py +134 -0
- python2rust-0.1.0/tests/core/test_api.py +339 -0
- python2rust-0.1.0/tests/core/test_clean_invariant.py +339 -0
- python2rust-0.1.0/tests/core/test_compile.py +153 -0
- python2rust-0.1.0/tests/core/test_config_and_context.py +110 -0
- python2rust-0.1.0/tests/core/test_constructs.py +57 -0
- python2rust-0.1.0/tests/core/test_equivalence.py +391 -0
- python2rust-0.1.0/tests/core/test_golden.py +84 -0
- python2rust-0.1.0/tests/core/test_hostile.py +81 -0
- python2rust-0.1.0/tests/core/test_hygiene.py +35 -0
- python2rust-0.1.0/tests/core/test_module_init.py +76 -0
- python2rust-0.1.0/tests/core/test_no_exec.py +134 -0
- python2rust-0.1.0/tests/core/test_programs.py +117 -0
- python2rust-0.1.0/tests/core/test_project.py +162 -0
- python2rust-0.1.0/tests/core/test_pytest_lowering.py +111 -0
- python2rust-0.1.0/tests/core/test_runtime_crate.py +48 -0
- python2rust-0.1.0/tests/data/any_types.py +10 -0
- python2rust-0.1.0/tests/data/any_types.rs +40 -0
- python2rust-0.1.0/tests/data/constants.py +12 -0
- python2rust-0.1.0/tests/data/constants.rs +29 -0
- python2rust-0.1.0/tests/data/dataclass_basic.py +15 -0
- python2rust-0.1.0/tests/data/dataclass_basic.rs +30 -0
- python2rust-0.1.0/tests/data/doctest_dropped.py +18 -0
- python2rust-0.1.0/tests/data/doctest_dropped.rs +36 -0
- python2rust-0.1.0/tests/data/enum_int_auto.py +17 -0
- python2rust-0.1.0/tests/data/enum_int_auto.rs +25 -0
- python2rust-0.1.0/tests/data/enum_str.py +12 -0
- python2rust-0.1.0/tests/data/enum_str.rs +22 -0
- python2rust-0.1.0/tests/data/equiv_async.py +35 -0
- python2rust-0.1.0/tests/data/equiv_async.rs +59 -0
- python2rust-0.1.0/tests/data/equiv_library.py +51 -0
- python2rust-0.1.0/tests/data/equiv_library.rs +75 -0
- python2rust-0.1.0/tests/data/equiv_models.py +81 -0
- python2rust-0.1.0/tests/data/equiv_models.rs +223 -0
- python2rust-0.1.0/tests/data/equiv_names.py +18 -0
- python2rust-0.1.0/tests/data/equiv_names.rs +24 -0
- python2rust-0.1.0/tests/data/equiv_semantics.py +314 -0
- python2rust-0.1.0/tests/data/equiv_semantics.rs +603 -0
- python2rust-0.1.0/tests/data/equiv_stdlib.py +78 -0
- python2rust-0.1.0/tests/data/equiv_stdlib.rs +132 -0
- python2rust-0.1.0/tests/data/equiv_trial.py +150 -0
- python2rust-0.1.0/tests/data/equiv_trial.rs +233 -0
- python2rust-0.1.0/tests/data/equiv_validation.py +54 -0
- python2rust-0.1.0/tests/data/equiv_validation.rs +350 -0
- python2rust-0.1.0/tests/data/exc_basic.py +40 -0
- python2rust-0.1.0/tests/data/exc_basic.rs +93 -0
- python2rust-0.1.0/tests/data/exc_flow.py +155 -0
- python2rust-0.1.0/tests/data/exc_flow.rs +421 -0
- python2rust-0.1.0/tests/data/fn_arith.py +30 -0
- python2rust-0.1.0/tests/data/fn_arith.rs +36 -0
- python2rust-0.1.0/tests/data/fn_augassign.py +18 -0
- python2rust-0.1.0/tests/data/fn_augassign.rs +38 -0
- python2rust-0.1.0/tests/data/fn_builtins.py +19 -0
- python2rust-0.1.0/tests/data/fn_builtins.rs +54 -0
- python2rust-0.1.0/tests/data/fn_comprehensions.py +42 -0
- python2rust-0.1.0/tests/data/fn_comprehensions.rs +146 -0
- python2rust-0.1.0/tests/data/fn_conditionals.py +31 -0
- python2rust-0.1.0/tests/data/fn_conditionals.rs +43 -0
- python2rust-0.1.0/tests/data/fn_default_args.py +14 -0
- python2rust-0.1.0/tests/data/fn_default_args.rs +26 -0
- python2rust-0.1.0/tests/data/fn_dict_methods.py +42 -0
- python2rust-0.1.0/tests/data/fn_dict_methods.rs +99 -0
- python2rust-0.1.0/tests/data/fn_floordiv_mod.py +18 -0
- python2rust-0.1.0/tests/data/fn_floordiv_mod.rs +24 -0
- python2rust-0.1.0/tests/data/fn_fstrings.py +26 -0
- python2rust-0.1.0/tests/data/fn_fstrings.rs +51 -0
- python2rust-0.1.0/tests/data/fn_hoisting.py +31 -0
- python2rust-0.1.0/tests/data/fn_hoisting.rs +46 -0
- python2rust-0.1.0/tests/data/fn_iteration.py +38 -0
- python2rust-0.1.0/tests/data/fn_iteration.rs +90 -0
- python2rust-0.1.0/tests/data/fn_lambda.py +12 -0
- python2rust-0.1.0/tests/data/fn_lambda.rs +35 -0
- python2rust-0.1.0/tests/data/fn_list_methods.py +44 -0
- python2rust-0.1.0/tests/data/fn_list_methods.rs +92 -0
- python2rust-0.1.0/tests/data/fn_loops.py +48 -0
- python2rust-0.1.0/tests/data/fn_loops.rs +70 -0
- python2rust-0.1.0/tests/data/fn_match.py +28 -0
- python2rust-0.1.0/tests/data/fn_match.rs +47 -0
- python2rust-0.1.0/tests/data/fn_match_enum.py +28 -0
- python2rust-0.1.0/tests/data/fn_match_enum.rs +48 -0
- python2rust-0.1.0/tests/data/fn_model_construct.py +34 -0
- python2rust-0.1.0/tests/data/fn_model_construct.rs +104 -0
- python2rust-0.1.0/tests/data/fn_mutation_params.py +25 -0
- python2rust-0.1.0/tests/data/fn_mutation_params.rs +37 -0
- python2rust-0.1.0/tests/data/fn_optional.py +34 -0
- python2rust-0.1.0/tests/data/fn_optional.rs +46 -0
- python2rust-0.1.0/tests/data/fn_sets.py +20 -0
- python2rust-0.1.0/tests/data/fn_sets.rs +42 -0
- python2rust-0.1.0/tests/data/fn_slicing.py +38 -0
- python2rust-0.1.0/tests/data/fn_slicing.rs +48 -0
- python2rust-0.1.0/tests/data/fn_strings.py +42 -0
- python2rust-0.1.0/tests/data/fn_strings.rs +76 -0
- python2rust-0.1.0/tests/data/fn_truthiness.py +10 -0
- python2rust-0.1.0/tests/data/fn_truthiness.rs +30 -0
- python2rust-0.1.0/tests/data/fn_unpack.py +21 -0
- python2rust-0.1.0/tests/data/fn_unpack.rs +35 -0
- python2rust-0.1.0/tests/data/fn_variadic.py +17 -0
- python2rust-0.1.0/tests/data/fn_variadic.rs +47 -0
- python2rust-0.1.0/tests/data/fn_walrus.py +18 -0
- python2rust-0.1.0/tests/data/fn_walrus.rs +35 -0
- python2rust-0.1.0/tests/data/hostile_comments.py +11 -0
- python2rust-0.1.0/tests/data/hostile_comments.rs +14 -0
- python2rust-0.1.0/tests/data/hostile_huge_literal.py +5 -0
- python2rust-0.1.0/tests/data/hostile_huge_literal.rs +42 -0
- python2rust-0.1.0/tests/data/hostile_unicode.py +10 -0
- python2rust-0.1.0/tests/data/hostile_unicode.rs +13 -0
- python2rust-0.1.0/tests/data/lexleak/include.rs +1 -0
- python2rust-0.1.0/tests/data/lexleak/include_bytes.rs +2 -0
- python2rust-0.1.0/tests/data/literal_fields.py +12 -0
- python2rust-0.1.0/tests/data/literal_fields.rs +67 -0
- python2rust-0.1.0/tests/data/model_alias.py +10 -0
- python2rust-0.1.0/tests/data/model_alias.rs +60 -0
- python2rust-0.1.0/tests/data/model_basic.py +11 -0
- python2rust-0.1.0/tests/data/model_basic.rs +85 -0
- python2rust-0.1.0/tests/data/model_inherit.py +14 -0
- python2rust-0.1.0/tests/data/model_inherit.rs +127 -0
- python2rust-0.1.0/tests/data/model_nested.py +16 -0
- python2rust-0.1.0/tests/data/model_nested.rs +90 -0
- python2rust-0.1.0/tests/data/model_optional_defaults.py +14 -0
- python2rust-0.1.0/tests/data/model_optional_defaults.rs +109 -0
- python2rust-0.1.0/tests/data/module_values.py +46 -0
- python2rust-0.1.0/tests/data/module_values.rs +116 -0
- python2rust-0.1.0/tests/data/namedtuple_basic.py +7 -0
- python2rust-0.1.0/tests/data/namedtuple_basic.rs +16 -0
- python2rust-0.1.0/tests/data/neg_alias_stores.py +73 -0
- python2rust-0.1.0/tests/data/neg_alias_stores.rs +88 -0
- python2rust-0.1.0/tests/data/neg_aliasing.py +4 -0
- python2rust-0.1.0/tests/data/neg_aliasing.rs +10 -0
- python2rust-0.1.0/tests/data/neg_async.py +10 -0
- python2rust-0.1.0/tests/data/neg_async.rs +13 -0
- python2rust-0.1.0/tests/data/neg_class.py +7 -0
- python2rust-0.1.0/tests/data/neg_class.rs +6 -0
- python2rust-0.1.0/tests/data/neg_decorator.py +10 -0
- python2rust-0.1.0/tests/data/neg_decorator.rs +15 -0
- python2rust-0.1.0/tests/data/neg_for_else.py +7 -0
- python2rust-0.1.0/tests/data/neg_for_else.rs +10 -0
- python2rust-0.1.0/tests/data/neg_format_hex.py +2 -0
- python2rust-0.1.0/tests/data/neg_format_hex.rs +9 -0
- python2rust-0.1.0/tests/data/neg_frozen_assign.py +27 -0
- python2rust-0.1.0/tests/data/neg_frozen_assign.rs +52 -0
- python2rust-0.1.0/tests/data/neg_generator.py +3 -0
- python2rust-0.1.0/tests/data/neg_generator.rs +6 -0
- python2rust-0.1.0/tests/data/neg_imports.py +18 -0
- python2rust-0.1.0/tests/data/neg_imports.rs +23 -0
- python2rust-0.1.0/tests/data/neg_late_binding.py +16 -0
- python2rust-0.1.0/tests/data/neg_late_binding.rs +26 -0
- python2rust-0.1.0/tests/data/neg_literal_int.py +7 -0
- python2rust-0.1.0/tests/data/neg_literal_int.rs +35 -0
- python2rust-0.1.0/tests/data/neg_loop_leak.py +4 -0
- python2rust-0.1.0/tests/data/neg_loop_leak.rs +12 -0
- python2rust-0.1.0/tests/data/neg_match_class.py +6 -0
- python2rust-0.1.0/tests/data/neg_match_class.rs +9 -0
- python2rust-0.1.0/tests/data/neg_model_methods.py +18 -0
- python2rust-0.1.0/tests/data/neg_model_methods.rs +49 -0
- python2rust-0.1.0/tests/data/neg_module_state.py +11 -0
- python2rust-0.1.0/tests/data/neg_module_state.rs +39 -0
- python2rust-0.1.0/tests/data/neg_module_value.py +5 -0
- python2rust-0.1.0/tests/data/neg_module_value.rs +26 -0
- python2rust-0.1.0/tests/data/neg_mutable_default.py +7 -0
- python2rust-0.1.0/tests/data/neg_mutable_default.rs +14 -0
- python2rust-0.1.0/tests/data/neg_optional_narrowing.py +6 -0
- python2rust-0.1.0/tests/data/neg_optional_narrowing.rs +13 -0
- python2rust-0.1.0/tests/data/neg_raise.py +4 -0
- python2rust-0.1.0/tests/data/neg_raise.rs +14 -0
- python2rust-0.1.0/tests/data/neg_scoping.py +13 -0
- python2rust-0.1.0/tests/data/neg_scoping.rs +17 -0
- python2rust-0.1.0/tests/data/neg_star_args.py +6 -0
- python2rust-0.1.0/tests/data/neg_star_args.rs +15 -0
- python2rust-0.1.0/tests/data/neg_try.py +16 -0
- python2rust-0.1.0/tests/data/neg_try.rs +54 -0
- python2rust-0.1.0/tests/data/neg_unannotated.py +10 -0
- python2rust-0.1.0/tests/data/neg_unannotated.rs +18 -0
- python2rust-0.1.0/tests/data/neg_unknown_calls.py +8 -0
- python2rust-0.1.0/tests/data/neg_unknown_calls.rs +17 -0
- python2rust-0.1.0/tests/data/neg_unknown_types.py +12 -0
- python2rust-0.1.0/tests/data/neg_unknown_types.rs +31 -0
- python2rust-0.1.0/tests/data/neg_walrus_late.py +6 -0
- python2rust-0.1.0/tests/data/neg_walrus_late.rs +11 -0
- python2rust-0.1.0/tests/data/neg_with.py +3 -0
- python2rust-0.1.0/tests/data/neg_with.rs +9 -0
- python2rust-0.1.0/tests/data/newtype_alias.py +8 -0
- python2rust-0.1.0/tests/data/newtype_alias.rs +25 -0
- python2rust-0.1.0/tests/data/programs/08_multiple_of.py +20 -0
- python2rust-0.1.0/tests/data/programs/09_model_setattr.py +18 -0
- python2rust-0.1.0/tests/data/programs/10_setattr_variants.py +39 -0
- python2rust-0.1.0/tests/data/programs/11_dump.py +34 -0
- python2rust-0.1.0/tests/data/programs/12_mixed_literal.py +24 -0
- python2rust-0.1.0/tests/data/programs/13_int_as_float.py +22 -0
- python2rust-0.1.0/tests/data/programs/13b_int_as_float_silent.py +17 -0
- python2rust-0.1.0/tests/data/programs/15_decorator.py +14 -0
- python2rust-0.1.0/tests/data/programs/16_idents.py +14 -0
- python2rust-0.1.0/tests/data/programs/17_validator.py +32 -0
- python2rust-0.1.0/tests/data/programs/18_validator_construct.py +22 -0
- python2rust-0.1.0/tests/data/programs/19_inherited_validator.py +25 -0
- python2rust-0.1.0/tests/data/programs/20_exc.py +80 -0
- python2rust-0.1.0/tests/data/programs/21_async.py +28 -0
- python2rust-0.1.0/tests/data/programs/22_features.py +24 -0
- python2rust-0.1.0/tests/data/programs/23_array_as_model.py +20 -0
- python2rust-0.1.0/tests/data/programs/24_exc_texts.py +62 -0
- python2rust-0.1.0/tests/data/programs/25_neg_zero.py +15 -0
- python2rust-0.1.0/tests/data/programs/26_attr_assign.py +37 -0
- python2rust-0.1.0/tests/data/programs/27_held_coroutine.py +29 -0
- python2rust-0.1.0/tests/data/programs/28_model_json_shapes.py +34 -0
- python2rust-0.1.0/tests/data/programs/29_alias_patterns.py +56 -0
- python2rust-0.1.0/tests/data/programs/30_builtin_errors.py +62 -0
- python2rust-0.1.0/tests/data/programs/r3_a01_async.py +23 -0
- python2rust-0.1.0/tests/data/programs/r3_a02_async_order.py +16 -0
- python2rust-0.1.0/tests/data/programs/r3_n01_order.py +10 -0
- python2rust-0.1.0/tests/data/programs/r3_n02_fmt.py +16 -0
- python2rust-0.1.0/tests/data/programs/r3_n03_print.py +17 -0
- python2rust-0.1.0/tests/data/programs/r3_n04_coll.py +31 -0
- python2rust-0.1.0/tests/data/programs/r3_n05_closures.py +30 -0
- python2rust-0.1.0/tests/data/programs/r3_n06_defaults.py +15 -0
- python2rust-0.1.0/tests/data/programs/r3_n07_exc.py +66 -0
- python2rust-0.1.0/tests/data/programs/r3_n08_globals.py +23 -0
- python2rust-0.1.0/tests/data/programs/r3_n09_reassign.py +10 -0
- python2rust-0.1.0/tests/data/programs/r3_n10_lazy.py +15 -0
- python2rust-0.1.0/tests/data/programs/r3_n11_modloop.py +4 -0
- python2rust-0.1.0/tests/data/programs/r3_n12_once.py +13 -0
- python2rust-0.1.0/tests/data/programs/r3_n13_sem.py +62 -0
- python2rust-0.1.0/tests/data/programs/r3_n14_latebind.py +35 -0
- python2rust-0.1.0/tests/data/programs/r3_n15_keyerr.py +26 -0
- python2rust-0.1.0/tests/data/programs/r3_n15b_keyerr.py +14 -0
- python2rust-0.1.0/tests/data/programs/r3_n16_exc2.py +48 -0
- python2rust-0.1.0/tests/data/programs/r3_n17_mutarg.py +35 -0
- python2rust-0.1.0/tests/data/programs/r3_n18_alias2.py +43 -0
- python2rust-0.1.0/tests/data/programs/r3_n18b_alias.py +43 -0
- python2rust-0.1.0/tests/data/programs/r3_n19_container_alias.py +13 -0
- python2rust-0.1.0/tests/data/programs/r3_n20_loop_mut.py +19 -0
- python2rust-0.1.0/tests/data/programs/r3_n21_stub_unreached.py +9 -0
- python2rust-0.1.0/tests/data/programs/r3_n22_custom_exc_init.py +17 -0
- python2rust-0.1.0/tests/data/programs/r3_p01_models.py +49 -0
- python2rust-0.1.0/tests/data/programs/r3_p01b_models.py +48 -0
- python2rust-0.1.0/tests/data/programs/r3_p02_constraints.py +44 -0
- python2rust-0.1.0/tests/data/programs/r3_p03_validators.py +29 -0
- python2rust-0.1.0/tests/data/programs/r3_p04_construct.py +29 -0
- python2rust-0.1.0/tests/data/programs/r3_p05_wire.py +20 -0
- python2rust-0.1.0/tests/data/programs/r3_p06_schema.py +14 -0
- python2rust-0.1.0/tests/data/programs/r3_p07_frozen.py +46 -0
- python2rust-0.1.0/tests/data/programs/r3_p08_frozen_aug.py +30 -0
- python2rust-0.1.0/tests/data/programs/r4_c01_classes.py +58 -0
- python2rust-0.1.0/tests/data/programs/r4_e01_three_levels.py +24 -0
- python2rust-0.1.0/tests/data/programs/r4_e02_order.py +35 -0
- python2rust-0.1.0/tests/data/programs/r4_e03_comp_keyerr.py +21 -0
- python2rust-0.1.0/tests/data/programs/r4_e04_finally.py +32 -0
- python2rust-0.1.0/tests/data/programs/r4_e05_helper_int.py +22 -0
- python2rust-0.1.0/tests/data/programs/r4_e06_reraise.py +25 -0
- python2rust-0.1.0/tests/data/programs/r4_e07_repr_exc.py +35 -0
- python2rust-0.1.0/tests/data/programs/r4_e08_repr_exc_clean.py +35 -0
- python2rust-0.1.0/tests/data/programs/r4_e09_comp_keyerr.py +32 -0
- python2rust-0.1.0/tests/data/programs/r4_i01_init_order.py +17 -0
- python2rust-0.1.0/tests/data/programs/r4_i02_init_late.py +16 -0
- python2rust-0.1.0/tests/data/programs/r4_i03_init_late_err.py +17 -0
- python2rust-0.1.0/tests/data/programs/r4_i04_argv.py +10 -0
- python2rust-0.1.0/tests/data/programs/r4_i05_counter.py +11 -0
- python2rust-0.1.0/tests/data/programs/r4_i06_global_counter.py +17 -0
- python2rust-0.1.0/tests/data/programs/r4_i07_dict_const.py +14 -0
- python2rust-0.1.0/tests/data/programs/r4_i08_nameerror.py +15 -0
- python2rust-0.1.0/tests/data/programs/r4_i09_order_values.py +16 -0
- python2rust-0.1.0/tests/data/programs/r4_k01_compile.py +101 -0
- python2rust-0.1.0/tests/data/programs/r4_k02_compile.py +101 -0
- python2rust-0.1.0/tests/data/programs/r4_k03_underscore_fn.py +2 -0
- python2rust-0.1.0/tests/data/programs/r4_s01_repr.py +33 -0
- python2rust-0.1.0/tests/data/programs/r4_s02_sem.py +55 -0
- python2rust-0.1.0/tests/data/programs/r4_s02b_sem.py +40 -0
- python2rust-0.1.0/tests/data/programs/r4_x01_callee_store.py +19 -0
- python2rust-0.1.0/tests/data/programs/r4_x02_setdefault.py +19 -0
- python2rust-0.1.0/tests/data/programs/r4_x03_return_self.py +17 -0
- python2rust-0.1.0/tests/data/programs/r4_x04_nested.py +14 -0
- python2rust-0.1.0/tests/data/programs/r4_x05_tuple_unpack.py +14 -0
- python2rust-0.1.0/tests/data/programs/r4_x06_chain_assign.py +18 -0
- python2rust-0.1.0/tests/data/programs/r4_x07_default_arg.py +12 -0
- python2rust-0.1.0/tests/data/programs/r4_x08_sorted.py +18 -0
- python2rust-0.1.0/tests/data/programs/r4_x09_model_nested.py +26 -0
- python2rust-0.1.0/tests/data/programs/r4_x10_attr_chain.py +23 -0
- python2rust-0.1.0/tests/data/programs/r4_x11_iter_mut.py +16 -0
- python2rust-0.1.0/tests/data/programs/r4_x12_augadd.py +16 -0
- python2rust-0.1.0/tests/data/programs/r4_x13_obj_list.py +20 -0
- python2rust-0.1.0/tests/data/programs/r4_y01_alias_dc.py +99 -0
- python2rust-0.1.0/tests/data/programs/r4_y01b.py +80 -0
- python2rust-0.1.0/tests/data/programs/r4_y02_callee_store_min.py +22 -0
- python2rust-0.1.0/tests/data/programs/r4_y03_escapes.py +111 -0
- python2rust-0.1.0/tests/data/programs/r4_y04_escapes_clean.py +94 -0
- python2rust-0.1.0/tests/data/programs/r4_y05_param_nested_mut.py +26 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/__init__.py +2 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/broken.py +7 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/errors.py +6 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/models.py +16 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/pricing.py +15 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/pytest_pricing.py +14 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/report.py +21 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/util/__init__.py +1 -0
- python2rust-0.1.0/tests/data/projects/shop/shop/util/text.py +2 -0
- python2rust-0.1.0/tests/data/py2many_cases/assert.py +18 -0
- python2rust-0.1.0/tests/data/py2many_cases/assert.py2many.rs +48 -0
- python2rust-0.1.0/tests/data/py2many_cases/async.py +23 -0
- python2rust-0.1.0/tests/data/py2many_cases/asyncio_case.py +16 -0
- python2rust-0.1.0/tests/data/py2many_cases/asyncio_case.py2many.rs +50 -0
- python2rust-0.1.0/tests/data/py2many_cases/binit.py +87 -0
- python2rust-0.1.0/tests/data/py2many_cases/binit.py2many.rs +71 -0
- python2rust-0.1.0/tests/data/py2many_cases/bitops.py +22 -0
- python2rust-0.1.0/tests/data/py2many_cases/bitops.py2many.rs +56 -0
- python2rust-0.1.0/tests/data/py2many_cases/bubble_sort.py +20 -0
- python2rust-0.1.0/tests/data/py2many_cases/bubble_sort.py2many.rs +58 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/async_locals_and_strings.py +38 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/chained_compare_kwargs_defaults.py +28 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/closure_capture_and_loop_else.py +59 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/floor_div_mod_negative.py +29 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/mutation_detection.py +49 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/strip_split_enumerate_args.py +38 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/tuple_swap_in_loop.py +26 -0
- python2rust-0.1.0/tests/data/py2many_cases/bug_repros/unicode_len_find_slice.py +35 -0
- python2rust-0.1.0/tests/data/py2many_cases/built_ins.py +21 -0
- python2rust-0.1.0/tests/data/py2many_cases/built_ins.py2many.rs +58 -0
- python2rust-0.1.0/tests/data/py2many_cases/byte_literals.py +10 -0
- python2rust-0.1.0/tests/data/py2many_cases/byte_literals.py2many.rs +42 -0
- python2rust-0.1.0/tests/data/py2many_cases/classes.py +14 -0
- python2rust-0.1.0/tests/data/py2many_cases/classes.py2many.rs +52 -0
- python2rust-0.1.0/tests/data/py2many_cases/cls.py +10 -0
- python2rust-0.1.0/tests/data/py2many_cases/cls.py2many.rs +47 -0
- python2rust-0.1.0/tests/data/py2many_cases/comb_sort.py +25 -0
- python2rust-0.1.0/tests/data/py2many_cases/comb_sort.py2many.rs +63 -0
- python2rust-0.1.0/tests/data/py2many_cases/comment_unsupported.py +15 -0
- python2rust-0.1.0/tests/data/py2many_cases/comment_unsupported.py2many.rs +45 -0
- python2rust-0.1.0/tests/data/py2many_cases/comparison.py +26 -0
- python2rust-0.1.0/tests/data/py2many_cases/complex.py +19 -0
- python2rust-0.1.0/tests/data/py2many_cases/coverage.py +95 -0
- python2rust-0.1.0/tests/data/py2many_cases/coverage.py2many.rs +132 -0
- python2rust-0.1.0/tests/data/py2many_cases/datatypes.py +17 -0
- python2rust-0.1.0/tests/data/py2many_cases/datatypes_base.py +9 -0
- python2rust-0.1.0/tests/data/py2many_cases/delete.py +17 -0
- python2rust-0.1.0/tests/data/py2many_cases/demorgan.py +14 -0
- python2rust-0.1.0/tests/data/py2many_cases/demorgan2.py +16 -0
- python2rust-0.1.0/tests/data/py2many_cases/dependent_types.py +15 -0
- python2rust-0.1.0/tests/data/py2many_cases/dict.py +32 -0
- python2rust-0.1.0/tests/data/py2many_cases/dict.py2many.rs +69 -0
- python2rust-0.1.0/tests/data/py2many_cases/dict_comp.py +15 -0
- python2rust-0.1.0/tests/data/py2many_cases/equations.py +27 -0
- python2rust-0.1.0/tests/data/py2many_cases/equations2.py +30 -0
- python2rust-0.1.0/tests/data/py2many_cases/exception_names.py +12 -0
- python2rust-0.1.0/tests/data/py2many_cases/exceptions.py +24 -0
- python2rust-0.1.0/tests/data/py2many_cases/fib.py +11 -0
- python2rust-0.1.0/tests/data/py2many_cases/fib.py2many.rs +45 -0
- python2rust-0.1.0/tests/data/py2many_cases/fib_with_argparse.py +24 -0
- python2rust-0.1.0/tests/data/py2many_cases/fib_with_argparse.py2many.rs +64 -0
- python2rust-0.1.0/tests/data/py2many_cases/fstring.py +5 -0
- python2rust-0.1.0/tests/data/py2many_cases/fstring.py2many.rs +43 -0
- python2rust-0.1.0/tests/data/py2many_cases/gen_exp.py +12 -0
- python2rust-0.1.0/tests/data/py2many_cases/gen_exp.py2many.rs +45 -0
- python2rust-0.1.0/tests/data/py2many_cases/generator.py +19 -0
- python2rust-0.1.0/tests/data/py2many_cases/global.py +20 -0
- python2rust-0.1.0/tests/data/py2many_cases/global.py2many.rs +53 -0
- python2rust-0.1.0/tests/data/py2many_cases/global2.py +19 -0
- python2rust-0.1.0/tests/data/py2many_cases/global2.py2many.rs +57 -0
- python2rust-0.1.0/tests/data/py2many_cases/hello_world.py +5 -0
- python2rust-0.1.0/tests/data/py2many_cases/hello_world.py2many.rs +39 -0
- python2rust-0.1.0/tests/data/py2many_cases/ifexp.py +12 -0
- python2rust-0.1.0/tests/data/py2many_cases/ifexp.py2many.rs +45 -0
- python2rust-0.1.0/tests/data/py2many_cases/import_tests.py +14 -0
- python2rust-0.1.0/tests/data/py2many_cases/import_tests.py2many.rs +46 -0
- python2rust-0.1.0/tests/data/py2many_cases/infer.py +13 -0
- python2rust-0.1.0/tests/data/py2many_cases/infer.py2many.rs +45 -0
- python2rust-0.1.0/tests/data/py2many_cases/infer_ops.py +91 -0
- python2rust-0.1.0/tests/data/py2many_cases/infer_ops.py2many.rs +109 -0
- python2rust-0.1.0/tests/data/py2many_cases/int_enum.py +34 -0
- python2rust-0.1.0/tests/data/py2many_cases/int_enum.py2many.rs +82 -0
- python2rust-0.1.0/tests/data/py2many_cases/invariants.py +27 -0
- python2rust-0.1.0/tests/data/py2many_cases/lambda.py +18 -0
- python2rust-0.1.0/tests/data/py2many_cases/lambda.py2many.rs +43 -0
- python2rust-0.1.0/tests/data/py2many_cases/lambda_walrus.py +16 -0
- python2rust-0.1.0/tests/data/py2many_cases/langcomp_bench.py +24 -0
- python2rust-0.1.0/tests/data/py2many_cases/langcomp_bench.py2many.rs +58 -0
- python2rust-0.1.0/tests/data/py2many_cases/loop.py +46 -0
- python2rust-0.1.0/tests/data/py2many_cases/loop.py2many.rs +92 -0
- python2rust-0.1.0/tests/data/py2many_cases/manifest.json +1895 -0
- python2rust-0.1.0/tests/data/py2many_cases/math_func.py +7 -0
- python2rust-0.1.0/tests/data/py2many_cases/nested_dict.py +11 -0
- python2rust-0.1.0/tests/data/py2many_cases/nested_dict.py2many.rs +50 -0
- python2rust-0.1.0/tests/data/py2many_cases/print.py +16 -0
- python2rust-0.1.0/tests/data/py2many_cases/print.py2many.rs +49 -0
- python2rust-0.1.0/tests/data/py2many_cases/rect.py +32 -0
- python2rust-0.1.0/tests/data/py2many_cases/rect.py2many.rs +65 -0
- python2rust-0.1.0/tests/data/py2many_cases/regex_methods.py +35 -0
- python2rust-0.1.0/tests/data/py2many_cases/scope.py +17 -0
- python2rust-0.1.0/tests/data/py2many_cases/sealed.py +28 -0
- python2rust-0.1.0/tests/data/py2many_cases/sealed.py2many.rs +80 -0
- python2rust-0.1.0/tests/data/py2many_cases/simple_lambda.py +7 -0
- python2rust-0.1.0/tests/data/py2many_cases/simple_lambda.py2many.rs +43 -0
- python2rust-0.1.0/tests/data/py2many_cases/smt_types.py +6 -0
- python2rust-0.1.0/tests/data/py2many_cases/starred.py +11 -0
- python2rust-0.1.0/tests/data/py2many_cases/stdio.py +14 -0
- python2rust-0.1.0/tests/data/py2many_cases/stdlib_str.py +28 -0
- python2rust-0.1.0/tests/data/py2many_cases/stdlib_str.py2many.rs +78 -0
- python2rust-0.1.0/tests/data/py2many_cases/str_enum.py +23 -0
- python2rust-0.1.0/tests/data/py2many_cases/str_enum.py2many.rs +72 -0
- python2rust-0.1.0/tests/data/py2many_cases/sudoku.py +129 -0
- python2rust-0.1.0/tests/data/py2many_cases/sudoku2.py +64 -0
- python2rust-0.1.0/tests/data/py2many_cases/sys_argv.py +15 -0
- python2rust-0.1.0/tests/data/py2many_cases/sys_argv.py2many.rs +52 -0
- python2rust-0.1.0/tests/data/py2many_cases/sys_exit.py +5 -0
- python2rust-0.1.0/tests/data/py2many_cases/sys_exit.py2many.rs +40 -0
- python2rust-0.1.0/tests/data/py2many_cases/test_dunder.py +42 -0
- python2rust-0.1.0/tests/data/py2many_cases/test_generators.py +51 -0
- python2rust-0.1.0/tests/data/py2many_cases/test_star.py +34 -0
- python2rust-0.1.0/tests/data/py2many_cases/test_walrus_simple.py +7 -0
- python2rust-0.1.0/tests/data/py2many_cases/triangle_buggy.py +96 -0
- python2rust-0.1.0/tests/data/py2many_cases/verified_sort.py +108 -0
- python2rust-0.1.0/tests/data/py2many_cases/verified_sort.py2many.rs +120 -0
- python2rust-0.1.0/tests/data/py2many_cases/walrus.py +17 -0
- python2rust-0.1.0/tests/data/py2many_cases/with.py +29 -0
- python2rust-0.1.0/tests/data/py2many_cases/with_open.py +13 -0
- python2rust-0.1.0/tests/data/py2many_cases/with_open.py2many.rs +61 -0
- python2rust-0.1.0/tests/data/py2many_cases/yield_from.py +23 -0
- python2rust-0.1.0/tests/data/pytest_dropped.py +59 -0
- python2rust-0.1.0/tests/data/pytest_dropped.rs +96 -0
- python2rust-0.1.0/tests/data/pytest_shapes.py +88 -0
- python2rust-0.1.0/tests/data/pytest_shapes.rs +228 -0
- python2rust-0.1.0/tests/data/schema_annotated.py +15 -0
- python2rust-0.1.0/tests/data/schema_annotated.rs +120 -0
- python2rust-0.1.0/tests/data/schema_constraints.py +17 -0
- python2rust-0.1.0/tests/data/schema_constraints.rs +186 -0
- python2rust-0.1.0/tests/data/schema_enums.py +24 -0
- python2rust-0.1.0/tests/data/schema_enums.rs +90 -0
- python2rust-0.1.0/tests/data/schema_query.py +11 -0
- python2rust-0.1.0/tests/data/schema_query.rs +64 -0
- python2rust-0.1.0/tests/data/schema_recursive.py +14 -0
- python2rust-0.1.0/tests/data/schema_recursive.rs +92 -0
- python2rust-0.1.0/tests/data/schema_types.py +20 -0
- python2rust-0.1.0/tests/data/schema_types.rs +80 -0
- python2rust-0.1.0/tests/data/script_entry.py +11 -0
- python2rust-0.1.0/tests/data/script_entry.rs +28 -0
- python2rust-0.1.0/tests/data/typeddict_basic.py +12 -0
- python2rust-0.1.0/tests/data/typeddict_basic.rs +20 -0
- python2rust-0.1.0/tests/data/union_fields.py +8 -0
- python2rust-0.1.0/tests/data/union_fields.rs +61 -0
- python2rust-0.1.0/tests/data/unittest_shapes.py +34 -0
- python2rust-0.1.0/tests/data/unittest_shapes.rs +78 -0
- python2rust-0.1.0/tests/data/untranslatable/unmapped.py +36 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/bool_is_int.py +48 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/cases.json +1096 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/chained_comparison.py +50 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/dict_order.py +58 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/exception_kinds.py +71 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/fib_tuple_swap.py +40 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/float_repr.py +48 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/floor_div_mod.py +44 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/int_overflow.py +54 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/kwargs_dropped.py +40 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/mutation_aliasing.py +61 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/negative_index.py +46 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/none_handling.py +53 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/round_half_even.py +40 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/sorted_stability.py +45 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/split_whitespace.py +44 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/str_repeat_negative.py +28 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/truthiness.py +51 -0
- python2rust-0.1.0/tests/data/wrong_but_compiles/unicode_slicing.py +48 -0
- python2rust-0.1.0/tests/fake_core.py +46 -0
- python2rust-0.1.0/tests/test_agents.py +216 -0
- python2rust-0.1.0/tests/test_apply_acceptance.py +482 -0
- python2rust-0.1.0/tests/test_apply_judged.py +221 -0
- python2rust-0.1.0/tests/test_apply_project.py +140 -0
- python2rust-0.1.0/tests/test_apply_tests.py +375 -0
- python2rust-0.1.0/tests/test_check.py +143 -0
- python2rust-0.1.0/tests/test_cli_contract.py +291 -0
- python2rust-0.1.0/tests/test_cli_sandbox.py +301 -0
- python2rust-0.1.0/tests/test_contract.py +558 -0
- python2rust-0.1.0/tests/test_core_contract.py +103 -0
- python2rust-0.1.0/tests/test_default_deps.py +145 -0
- python2rust-0.1.0/tests/test_deps_vetting.py +350 -0
- python2rust-0.1.0/tests/test_drift_ledger.py +62 -0
- python2rust-0.1.0/tests/test_equiv.py +910 -0
- python2rust-0.1.0/tests/test_equiv_builtin_errors.py +66 -0
- python2rust-0.1.0/tests/test_equiv_cli.py +221 -0
- python2rust-0.1.0/tests/test_equiv_compare.py +366 -0
- python2rust-0.1.0/tests/test_equiv_containers.py +100 -0
- python2rust-0.1.0/tests/test_equiv_judge.py +624 -0
- python2rust-0.1.0/tests/test_equiv_module_init.py +101 -0
- python2rust-0.1.0/tests/test_equiv_runner.py +439 -0
- python2rust-0.1.0/tests/test_equiv_types.py +263 -0
- python2rust-0.1.0/tests/test_eval.py +189 -0
- python2rust-0.1.0/tests/test_gate_gaps.py +102 -0
- python2rust-0.1.0/tests/test_gate_hostile.py +309 -0
- python2rust-0.1.0/tests/test_hard_error.py +56 -0
- python2rust-0.1.0/tests/test_keystore.py +77 -0
- python2rust-0.1.0/tests/test_loop.py +435 -0
- python2rust-0.1.0/tests/test_mcp.py +324 -0
- python2rust-0.1.0/tests/test_mcp_sandbox.py +439 -0
- python2rust-0.1.0/tests/test_never_silent.py +108 -0
- python2rust-0.1.0/tests/test_no_exec.py +517 -0
- python2rust-0.1.0/tests/test_not_clean.py +61 -0
- python2rust-0.1.0/tests/test_ops.py +132 -0
- python2rust-0.1.0/tests/test_patch_mac.py +214 -0
- python2rust-0.1.0/tests/test_patch_store_trust.py +172 -0
- python2rust-0.1.0/tests/test_patches.py +536 -0
- python2rust-0.1.0/tests/test_port.py +317 -0
- python2rust-0.1.0/tests/test_port_validation.py +133 -0
- python2rust-0.1.0/tests/test_project_mode.py +194 -0
- python2rust-0.1.0/tests/test_readme_constructs.py +43 -0
- python2rust-0.1.0/tests/test_review_floor.py +45 -0
- python2rust-0.1.0/tests/test_rustlex.py +246 -0
- python2rust-0.1.0/tests/test_stub_core.py +57 -0
- python2rust-0.1.0/tests/test_verify.py +139 -0
- python2rust-0.1.0/tests/test_workflow.py +846 -0
- python2rust-0.1.0/tests/test_workflow_gates.py +478 -0
- python2rust-0.1.0/tests/test_workflow_layout.py +123 -0
- python2rust-0.1.0/tests/test_workflow_project.py +183 -0
- python2rust-0.1.0/tests/test_wrong_but_compiles.py +220 -0
- python2rust-0.1.0/tools/mine_py2many.py +3630 -0
- python2rust-0.1.0/tools/readme_constructs.py +101 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Instructions for AI agents that **use** python2rust to port Python to Rust, and (at the end) for
|
|
4
|
+
agents that **work on** this repository. `python2rust skill` prints a self-contained version of the
|
|
5
|
+
first part, with the JSON contracts and a worked example.
|
|
6
|
+
|
|
7
|
+
## Start here
|
|
8
|
+
|
|
9
|
+
To port a project, follow this flow from the project root. Every command takes `--json`;
|
|
10
|
+
`uvx python2rust status --json` always names the phase and the exact next command, so run it whenever you are unsure.
|
|
11
|
+
|
|
12
|
+
1. `uvx python2rust init --questions --json` prints the interview: questions with `id`, `why_it_matters`,
|
|
13
|
+
`options` (each with its `consequence`), a `default` and `ask_human`.
|
|
14
|
+
2. **Ask the human ALL the questions in ONE message.** Show every question with its options, the consequences and the
|
|
15
|
+
default. Skip a question whose `only_if` does not hold. Questions with `ask_human: true` need the human's
|
|
16
|
+
decision. For the others, show the default and let the human override it.
|
|
17
|
+
3. Put the answers in `answers.json` (`{"question id": value}`; lists for `multi` and `list` questions) and run
|
|
18
|
+
`uvx python2rust init --answers answers.json` (or repeated `--answer id=value`). A wrong id or value is exit 2 and
|
|
19
|
+
names the allowed values. This writes `python2rust.toml` and `.python2rust/state.json`.
|
|
20
|
+
4. `uvx python2rust plan --json` orders the units (import cycles are one unit, leaves first) and writes
|
|
21
|
+
`.python2rust/plan.json`.
|
|
22
|
+
5. Loop until `status` says `complete`: `uvx python2rust next --json` returns one unit as a brief (files, tests,
|
|
23
|
+
decisions, exact commands, acceptance criteria) and refreshes `PORTING.md`; port the unit with the commands in the
|
|
24
|
+
brief (`port`, `todos`, `apply`, `verify`; they work on the whole project and narrow to the unit
|
|
25
|
+
with `--unit UNIT`, so imports between units resolve and the crate keeps every unit); then `uvx python2rust done UNIT --json`. Exit 1 lists exactly what is
|
|
26
|
+
missing: fix it and run `done` again.
|
|
27
|
+
6. Report: units done, what `done` could not verify, and the `review_queue` from `status`.
|
|
28
|
+
|
|
29
|
+
Never answer an `ask_human` question on the human's behalf. Use `--defaults` only when the human told you to take
|
|
30
|
+
the defaults, never pass `--force` or `--reviewed` yourself (a human confirms reviews with `done UNIT --reviewed`),
|
|
31
|
+
and never run `--run-python` unless the human answered `run_python: yes` (it executes their code). The
|
|
32
|
+
equivalence tier needs `done UNIT --run-python` on that run; without it `done` records the unit at the tier that
|
|
33
|
+
actually ran (`compiled` or `tested`, never `verified`) and prints the command to add the flag.
|
|
34
|
+
|
|
35
|
+
## Using python2rust in an agent loop
|
|
36
|
+
|
|
37
|
+
python2rust translates the typed subset of Python mechanically. What it cannot translate is never
|
|
38
|
+
dropped: it becomes a `todo!()` in the Rust and an entry in a machine-readable list. You close that
|
|
39
|
+
list.
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uvx python2rust doctor --json # python, rustfmt, cargo, config
|
|
43
|
+
uvx python2rust translate src/ -o rust/ --json # 1. translate (exit 1 = TODOs remain)
|
|
44
|
+
uvx python2rust todos src/ -o rust/ --json # 2. the work list, one object per TODO
|
|
45
|
+
# 3. for each TODO, submit ONLY the replacement for its todo!():
|
|
46
|
+
uvx python2rust apply <TODO_ID> --patch fix.rs --json # stored in .python2rust/patches/, gated and compiled
|
|
47
|
+
uvx python2rust check rust/ --deps-from Cargo.toml --json # 4. compile in a scratch crate
|
|
48
|
+
# 5. repeat 3-4; stop when check exits 0 and no TODO is left that you have not handled
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Or let the tool drive the loop: `uvx python2rust port src/ -o rust/` (a dry run that prints the tasks it would
|
|
52
|
+
send) and `... --agent cmd --agent-cmd "claude -p"` (or `--agent anthropic|openai|azure --model NAME`) to repair
|
|
53
|
+
with a model. Nothing leaves the machine unless `--agent` is set.
|
|
54
|
+
|
|
55
|
+
Exit codes, for every command: `0` ok, `1` TODOs or error diagnostics remain (or the result could not be
|
|
56
|
+
verified, for example without cargo), `2` usage error, `3` internal error (including a missing core), `4` the Rust
|
|
57
|
+
does not compile or verify (compile errors, a failing clippy/test/equiv rung, a fix rejected by `apply`). With `--json` stdout is exactly one JSON document (parse it, do not scrape text);
|
|
58
|
+
human text is on stderr. Nothing is interactive. `-` reads stdin.
|
|
59
|
+
|
|
60
|
+
### Rules
|
|
61
|
+
|
|
62
|
+
1. **Work from the todo, not from memory.** Each todo carries `python_snippet`, `rust_context`,
|
|
63
|
+
`rust_line` and an `instruction`. Follow the instruction literally: write the replacement for that
|
|
64
|
+
`todo!()` only (plus `use` lines), keep signatures, and submit it with `apply`.
|
|
65
|
+
2. **Never edit generated files. Submit fixes with `apply`.** Re-translating regenerates them and puts every
|
|
66
|
+
stored fix back, so re-translating is always safe. `apply` rejects a patch containing `todo!`,
|
|
67
|
+
`unimplemented!`, `unreachable!`, `unwrap`/`expect` (also as `Option::unwrap`), `panic!`, `loop {}`,
|
|
68
|
+
`#[allow]`/`#[expect]`, `Default::default()`/`T::default()` stand-ins, `process::exit`, `unsafe`,
|
|
69
|
+
`transmute`, `asm!`, `include*!`, `env!`, `#[path]` and build-script directives, and accepts one only if the
|
|
70
|
+
function it touches compiles, every translated test that uses the module passes (tests that reach another
|
|
71
|
+
open TODO are listed as `skipped-todo`; a TODO inside a test is refused) and, wherever it can be compared (a pure
|
|
72
|
+
function with a JSON-able signature), the output equals the Python's. That comparison runs the Python, so it
|
|
73
|
+
needs `--run-python` and the human's yes: without it an applicable function is `unverified` (stored, not
|
|
74
|
+
accepted). `--no-equiv` accepts at check+tests and records `equiv: opted-out` and a lower `verified_level`;
|
|
75
|
+
`not-applicable` (I/O, async, methods, non-JSON parameters) is accepted at check+tests and says why. `unverified`
|
|
76
|
+
is also what you get when cargo is missing or the tests cannot run. `cfg!` / `#[cfg(...)]` are rejected: a
|
|
77
|
+
patch must not behave differently under test. Do not look for ways around the gate, and NEVER edit or delete a test to make the Rust pass. Put project knowledge into
|
|
78
|
+
the `--config` TOML (`import_map`, `library_map`, `type_map`, `review_patterns`) and re-translate,
|
|
79
|
+
so the fix applies to every file and survives regeneration. Commit the hand-written Rust, not the
|
|
80
|
+
raw generator output.
|
|
81
|
+
3. **Check after every TODO.** If `check` reports more errors than before, revert the edit and try a
|
|
82
|
+
different approach. `cargo.status: "skipped"` means nothing was compiled: do not report success.
|
|
83
|
+
4. **Unknown code? `python2rust explain PY2RS<NNN>`** gives the meaning, the typical fix and a
|
|
84
|
+
before/after example. `python2rust constructs` lists what is and is not supported.
|
|
85
|
+
5. **Escalate, do not guess.** A todo with `needs_review: true`, anything in a security-sensitive area
|
|
86
|
+
(auth, crypto, secrets, subprocesses, ownership checks) and every `todo-by-design` construct
|
|
87
|
+
(dynamic attribute access, `**kwargs` forwarding, `eval`, shared mutable state) must be reviewed by a
|
|
88
|
+
human or a stronger model before it counts as done. Hand over the todo object unchanged.
|
|
89
|
+
6. **Compiling is not correct.** `check` proves the Rust type-checks, nothing more. For behaviour that
|
|
90
|
+
matters, add tests on both sides and run `verify --level equiv --run-python` (it executes the user's Python in
|
|
91
|
+
a child process with best-effort limits, not an OS sandbox, so only with the human's yes): it compares outputs and reports `passed`, `passed-judged`, `failed`
|
|
92
|
+
(with a shrunk counterexample), `needs-judgement` or `not-applicable` (untested, never a pass). A judged
|
|
93
|
+
pass on a `needs_review` function is never enough: it needs a rules-level pass or `--ack-review TODO_ID`.
|
|
94
|
+
`python2rust contract` (experimental) diffs a FastAPI app's OpenAPI document against the Rust one.
|
|
95
|
+
7. **Say what is left.** End every run with: files translated, TODOs closed, TODOs left (with ids),
|
|
96
|
+
items flagged for review, `check` status. Never claim "done" while any of these is open.
|
|
97
|
+
|
|
98
|
+
Smaller models do well on one todo at a time (the todo object is self-contained). Give a stronger
|
|
99
|
+
model the whole file when todos depend on each other or when `check` errors are in code you did not
|
|
100
|
+
touch.
|
|
101
|
+
|
|
102
|
+
An MCP server (`python2rust mcp`, `pip install 'python2rust[mcp]'`) exposes the same loop as tools:
|
|
103
|
+
`translate_source`, `list_todos`, `explain_diagnostic`, `check_rust`, `coverage`, `apply_patch`, plus the workflow
|
|
104
|
+
tools `init_questions`, `init_apply`, `plan`, `next_unit`, `mark_done` and `status`. The tools that run cargo
|
|
105
|
+
(`check_rust`, `apply_patch`, coverage levels check and above) are off unless the server is started with
|
|
106
|
+
`--allow-compile`: cargo executes code and these tools compile Rust a model supplied. Tell the human before
|
|
107
|
+
enabling it.
|
|
108
|
+
|
|
109
|
+
## Working on this repository
|
|
110
|
+
|
|
111
|
+
- This is a **public** project: no code, file names, import maps, URLs, secrets or fixtures from any
|
|
112
|
+
private codebase. Tests and examples use small synthetic Python. Project-specific mappings belong in a
|
|
113
|
+
user-supplied `--config` file outside the repo.
|
|
114
|
+
- Layout (one line per folder in `docs/ARCHITECTURE.md`): `src/python2rust/` has `cli/` (argparse
|
|
115
|
+
commands, `ops.py` shared with the MCP server), `verify/` (`check.py`, `ladder.py`, `equiv/`),
|
|
116
|
+
`agent/` (patch overlay and gate, `apply`, the repair loop, model backends), `workflow/` (init, plan,
|
|
117
|
+
next, done, status), `report/` (JSON Schemas, explain, constructs, eval, contract), `server/` (MCP),
|
|
118
|
+
`skill/`, and `core/` (the translator, behind the contract in `docs/ARCHITECTURE.md`). `tests/_stub_core.py` is a test-only stand-in core (never shipped); the suite
|
|
119
|
+
runs against the real core.
|
|
120
|
+
- Setup and checks: `uv sync`, `uv run pytest`, `uv run ruff check`, `uv run ruff format --check`,
|
|
121
|
+
`uv run ty check`, `uv build`.
|
|
122
|
+
- Keep the CLI fast to start: argparse and the standard library only; import the core and the MCP SDK
|
|
123
|
+
lazily inside the commands that need them.
|
|
124
|
+
- Changing a `--json` document means changing `schemas.py`, `skill/SKILL.md` and the contract tests in
|
|
125
|
+
the same commit. Diagnostic codes are append-only (`PY2RS<NNN>`); add an explanation to `explain.py`
|
|
126
|
+
for every new code.
|
|
127
|
+
- Never silently drop anything: an unsupported construct is a `todo!()` plus a diagnostic.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BMS Suisse
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
python2rust-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
python2rust
|
|
2
|
+
Copyright (c) 2026 BMS Suisse (see LICENSE)
|
|
3
|
+
|
|
4
|
+
This product includes material derived from py2many, which is licensed under the
|
|
5
|
+
MIT License. The material is listed below. The full license text of py2many is
|
|
6
|
+
reproduced after the list, as the MIT License requires.
|
|
7
|
+
|
|
8
|
+
py2many https://github.com/py2many/py2many (version 0.9)
|
|
9
|
+
Copyright (c) 2015 Lukas Martinelli
|
|
10
|
+
Copyright (c) 2019 Julian Konchunas
|
|
11
|
+
Copyright (c) 2020 Arun Sharma
|
|
12
|
+
|
|
13
|
+
py2many is itself based on pyrs by Julian Konchunas and on Py14 by Lukas
|
|
14
|
+
Martinelli (with the python-3 branch by Valentin Lorentz), according to the
|
|
15
|
+
"Project History" section of its README.
|
|
16
|
+
|
|
17
|
+
Derived material in this repository
|
|
18
|
+
-----------------------------------
|
|
19
|
+
|
|
20
|
+
1. src/python2rust/data/py2many_builtins.toml
|
|
21
|
+
A data file whose entries record, restate or correct the Rust mappings found in
|
|
22
|
+
py2many's Rust backend (pyrs/plugins.py, pyrs/transpiler.py, pyrs/inference.py,
|
|
23
|
+
pyrs/clike.py and py2many/clike.py). Entries marked origin = "py2many" are
|
|
24
|
+
derived from a py2many table; entries marked origin = "original" are not.
|
|
25
|
+
Generated by tools/mine_py2many.py.
|
|
26
|
+
|
|
27
|
+
2. tests/data/py2many_cases/*.py
|
|
28
|
+
Verbatim copies of py2many's tests/cases/*.py, used as input programs.
|
|
29
|
+
|
|
30
|
+
3. tests/data/py2many_cases/*.py2many.rs
|
|
31
|
+
Verbatim copies of py2many's tests/expected/*.rs. They are reference material
|
|
32
|
+
showing what py2many produced. They are not endorsed as correct translations.
|
|
33
|
+
|
|
34
|
+
4. tools/mine_py2many.py and docs/FROM_PY2MANY.md
|
|
35
|
+
Written for this project. They describe py2many's behaviour and reimplement no
|
|
36
|
+
py2many code; ideas are credited in the text.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
py2many license text (from py2many 0.9, LICENSE, verbatim)
|
|
40
|
+
-----------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
The MIT License (MIT)
|
|
43
|
+
|
|
44
|
+
Copyright (c) 2015 Lukas Martinelli
|
|
45
|
+
Copyright (c) 2019 Julian Konchunas
|
|
46
|
+
Copyright (c) 2020 Arun Sharma
|
|
47
|
+
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
49
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
50
|
+
in the Software without restriction, including without limitation the rights
|
|
51
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
52
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
53
|
+
furnished to do so, subject to the following conditions:
|
|
54
|
+
|
|
55
|
+
The above copyright notice and this permission notice shall be included in all
|
|
56
|
+
copies or substantial portions of the Software.
|
|
57
|
+
|
|
58
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
59
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
60
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
61
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
62
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
63
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
64
|
+
SOFTWARE.
|
|
65
|
+
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python2rust
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Typed-Python to Rust transpiler built to be driven by AI agents: machine-readable diagnostics, loud TODOs, a validation loop.
|
|
5
|
+
Keywords: python,rust,transpiler,ai-agents,mcp,code-migration
|
|
6
|
+
Author: BMS Suisse
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: NOTICE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Rust
|
|
15
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: pytest>=8 ; extra == 'dev'
|
|
18
|
+
Requires-Dist: ruff>=0.8 ; extra == 'dev'
|
|
19
|
+
Requires-Dist: ty ; extra == 'dev'
|
|
20
|
+
Requires-Dist: jsonschema>=4 ; extra == 'dev'
|
|
21
|
+
Requires-Dist: twine>=5 ; extra == 'dev'
|
|
22
|
+
Requires-Dist: mcp>=1.2 ; extra == 'dev'
|
|
23
|
+
Requires-Dist: hypothesis>=6 ; extra == 'dev'
|
|
24
|
+
Requires-Dist: pydantic>=2 ; extra == 'dev'
|
|
25
|
+
Requires-Dist: hypothesis>=6 ; extra == 'equiv'
|
|
26
|
+
Requires-Dist: mcp>=1.2 ; extra == 'mcp'
|
|
27
|
+
Requires-Python: >=3.14
|
|
28
|
+
Project-URL: Homepage, https://github.com/bmsuisse/python2rust
|
|
29
|
+
Project-URL: Repository, https://github.com/bmsuisse/python2rust
|
|
30
|
+
Project-URL: Issues, https://github.com/bmsuisse/python2rust/issues
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Provides-Extra: equiv
|
|
33
|
+
Provides-Extra: mcp
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
<div align="center">
|
|
37
|
+
|
|
38
|
+
<img src="docs/assets/logo.svg" alt="python2rust logo" width="128" height="128">
|
|
39
|
+
|
|
40
|
+
# python2rust
|
|
41
|
+
|
|
42
|
+
**Typed Python in, Rust out, built for AI agents.**
|
|
43
|
+
|
|
44
|
+
Translates the typed subset of Python to Rust, never silently, and hands everything it cannot do
|
|
45
|
+
to an agent as a precise, machine-readable task.
|
|
46
|
+
|
|
47
|
+
[](https://github.com/bmsuisse/python2rust/actions/workflows/ci.yml)
|
|
48
|
+

|
|
49
|
+

|
|
50
|
+

|
|
51
|
+
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
> **Alpha, work in progress, not yet on PyPI.** Pydantic models, dataclasses, enums, typed functions, exceptions
|
|
55
|
+
> (`try`/`except`/`raise`), basic `async`/`await` and multi-module projects (a directory becomes one crate)
|
|
56
|
+
> translate, with `utoipa` schemas, source maps and a checked-output runtime crate. Classes, generators, decorators,
|
|
57
|
+
> most of the async library (`gather`, tasks, locks) and most third-party libraries are still explicit `todo!()`s
|
|
58
|
+
> (`python2rust constructs` lists exactly what is covered; the status table below is generated from it).
|
|
59
|
+
> `verify --level equiv`, the `port` repair loop and the `init`/`plan`/`next` agent flow exist; mining existing
|
|
60
|
+
> tests, end-to-end runs and capture/replay are not built yet.
|
|
61
|
+
|
|
62
|
+
## Start here: tell your agent
|
|
63
|
+
|
|
64
|
+
Point any coding agent (Claude Code, Codex, ...) at this page and give it one line:
|
|
65
|
+
|
|
66
|
+
````text
|
|
67
|
+
Port <path/to/python/src> to Rust with python2rust (https://github.com/bmsuisse/python2rust). Read its README and
|
|
68
|
+
AGENTS.md, run `uvx python2rust init --questions --json`, ask me those questions in a single message, then follow
|
|
69
|
+
`uvx python2rust status --json` until it says done. Report what needs my review.
|
|
70
|
+
````
|
|
71
|
+
|
|
72
|
+
The tool carries the process, so the agent does not have to guess it. Every command takes `--json` (one JSON
|
|
73
|
+
document on stdout; exit `0` ok, `1` something is missing, `2` usage error, `3` internal error, `4` does not
|
|
74
|
+
verify), nothing is interactive:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
uvx python2rust init --questions --json # 1. the interview, as JSON
|
|
78
|
+
# the agent asks the human ALL questions in ONE message: options, consequences and defaults
|
|
79
|
+
uvx python2rust init --answers answers.json # 2. writes python2rust.toml and .python2rust/state.json
|
|
80
|
+
uvx python2rust plan --json # 3. units in dependency order, with difficulty and tests found
|
|
81
|
+
uvx python2rust next --json # 4. one unit as a brief: files, decisions, commands, acceptance
|
|
82
|
+
# port the unit with the commands from the brief (port, todos, apply, verify)
|
|
83
|
+
uvx python2rust done UNIT --json # 5. recorded only if the checks of your output tier pass
|
|
84
|
+
uvx python2rust status --json # any time: phase, blockers, the exact next command, review queue
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Repeat 4 and 5 until `status` says `complete`.
|
|
88
|
+
|
|
89
|
+
- **`init --questions`** asks about the goal of the port, the scope, how strict output equality must be (byte for
|
|
90
|
+
byte, functionally the same, or functionally the same with an AI judge for the leftovers; floats are compared
|
|
91
|
+
exactly unless you pick a tolerance), where trusted
|
|
92
|
+
examples come from, whether your code may be **run** (equivalence executes it) or **sent to a model** (nothing
|
|
93
|
+
leaves the machine unless you choose a backend), and a few style choices. Questions marked `ask_human` need
|
|
94
|
+
your decision: the agent must never answer them for you. `init --answers FILE`, repeated `--answer id=value`
|
|
95
|
+
or `--defaults` validate the answers (a bad id or value is exit 2 naming the allowed values) and write the
|
|
96
|
+
config. Re-running `init` refuses to overwrite unless you pass `--force`.
|
|
97
|
+
- **`plan`** reads the code with `ast` only (your code is never imported or run): import cycles become one unit,
|
|
98
|
+
units are ordered leaves first, easy first. Per unit it reports size, async code, exception classes, tests
|
|
99
|
+
found, an estimate of what translates mechanically, risk flags and a difficulty score with reasons.
|
|
100
|
+
- **`next`** hands over the next unit as a self-contained brief (JSON, or markdown without `--json`) and keeps
|
|
101
|
+
`PORTING.md` current: decisions from your answers, type and crate mapping notes, open questions. The brief's
|
|
102
|
+
commands (`port`, `todos`, `verify`, `apply`, `done`) all work on the whole planned project and narrow to the
|
|
103
|
+
unit with `--unit UNIT`: imports between units resolve, every unit stays in the one crate (`lib.rs` lists
|
|
104
|
+
them all, modules named from the project root: `shop/__init__.py` is `mod shop`) and the tests that import
|
|
105
|
+
the unit run.
|
|
106
|
+
- **`done UNIT`** runs the checks your output tier needs (`draft`: compiles; `verified`: plus the same output as
|
|
107
|
+
the Python, which executes your code and so needs `done UNIT --run-python` on that run, after you answered
|
|
108
|
+
`run_python: yes`; `production`: plus clippy and tests) and records the unit only if they pass. The recorded
|
|
109
|
+
tier says what actually ran (`compiled`, `tested`, `verified`, `production`): without `--run-python` a
|
|
110
|
+
`verified` unit is recorded as `compiled`, and `done` says equivalence was not verified and prints the
|
|
111
|
+
command to run. Otherwise it exits 1 with the exact list of what is missing (every `todo!()` left, wherever
|
|
112
|
+
it is).
|
|
113
|
+
Work flagged for human review stays in the review queue until a human runs `done UNIT --reviewed`.
|
|
114
|
+
- **`status`** always answers: phase (`init needed`, `plan needed`, `porting`, `verifying`, `complete`), current
|
|
115
|
+
unit, blockers, the exact next command, open questions and the review queue.
|
|
116
|
+
|
|
117
|
+
The same operations are MCP tools (`init_questions`, `init_apply`, `plan`, `next_unit`, `mark_done`, `status`).
|
|
118
|
+
|
|
119
|
+
## Why
|
|
120
|
+
|
|
121
|
+
Porting a large Python codebase to Rust is mostly mechanical work with a few hard parts. The usual tools
|
|
122
|
+
either approximate silently or give up on the file. python2rust is built around three rules:
|
|
123
|
+
|
|
124
|
+
- **Never silent.** Whatever it cannot translate becomes a loud `todo!()` in the output, a diagnostic with a
|
|
125
|
+
stable `PY2RS<NNN>` code, and a self-contained hand-off task. Nothing is dropped quietly.
|
|
126
|
+
- **Agent-first.** Every command speaks JSON, nothing is interactive, exit codes are documented, and it ships an
|
|
127
|
+
MCP server and a bundled agent skill. An agent can drive the whole loop without a human reading output.
|
|
128
|
+
- **Proven, not claimed.** Output is verified by a ladder (parse, format, `cargo check`, clippy, tests) and every
|
|
129
|
+
Rust line maps back to the Python line it came from.
|
|
130
|
+
|
|
131
|
+
## How it works
|
|
132
|
+
|
|
133
|
+
```mermaid
|
|
134
|
+
flowchart LR
|
|
135
|
+
A[Typed Python] --> B[translate]
|
|
136
|
+
B --> C[Rust + .todo.json + diagnostics]
|
|
137
|
+
C --> D{cargo check}
|
|
138
|
+
D -- errors --> E[fix each todo!: stored fix, compiler suggestion, or agent]
|
|
139
|
+
E --> D
|
|
140
|
+
D -- clean --> F[verified Rust]
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
1. `translate` produces Rust, a source map back to the Python, and one task per `todo!()`.
|
|
144
|
+
2. `check` and `verify` compile the result and map every error to a Python line.
|
|
145
|
+
3. An agent (or a person) fixes only what failed. Accepted fixes are stored under `.python2rust/patches/` and
|
|
146
|
+
re-applied on the next translate, so a fix is only ever paid for once.
|
|
147
|
+
4. Repeat until it compiles. `python2rust port` runs this loop for you.
|
|
148
|
+
|
|
149
|
+
**One command.** `python2rust port` translates, compiles the whole crate once per round, groups the errors per
|
|
150
|
+
function through the source map, and repairs only what fails, cheapest fixer first: a stored fix, the compiler's own
|
|
151
|
+
suggested edits, then a model, with a stronger one after a few failed rounds. Every candidate passes the anti-cheat
|
|
152
|
+
gate and a re-check before it is kept, and stops are explicit (converged, budget, no progress). It prints a JSON round
|
|
153
|
+
log (errors before and after, functions fixed per tier, tokens, seconds).
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
uvx python2rust port src/ -o rust/ # dry run: prints the tasks it WOULD send
|
|
157
|
+
uvx python2rust port src/ -o rust/ --agent cmd --agent-cmd "claude -p" # any CLI agent: task JSON in, patch JSON out
|
|
158
|
+
uvx python2rust port src/ -o rust/ --agent anthropic --model <model> # or openai / azure, keys from the environment
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Privacy.** Nothing leaves your machine unless you choose an `--agent`. Without one, `port` is a dry run that lists the
|
|
162
|
+
exact tasks (the Python function, the generated Rust, the compiler errors, signatures of the items it uses) and sends
|
|
163
|
+
nothing. With one, the same text is sent and a notice says so; prompts are only printed with `--verbose`.
|
|
164
|
+
|
|
165
|
+
## Status
|
|
166
|
+
|
|
167
|
+
**Alpha. Expect TODOs.** Trust `python2rust constructs` (what is covered) and `python2rust coverage src/` (how much
|
|
168
|
+
of *your* code translates) over this README.
|
|
169
|
+
|
|
170
|
+
- Typed Python only. Unannotated code produces placeholders and diagnostics, not guesses.
|
|
171
|
+
- Dynamic Python (`getattr` with computed names, `**kwargs` forwarding, `eval`, metaclasses, shared mutable state)
|
|
172
|
+
has no static Rust form. It is a TODO by design, always.
|
|
173
|
+
- A file that compiles is not a proven-equivalent file. `check` proves the Rust type-checks; behaviour needs tests
|
|
174
|
+
on both sides (`verify --level equiv` compares outputs, see [docs/EQUIVALENCE.md](docs/EQUIVALENCE.md)).
|
|
175
|
+
- **Security.** `translate`, `todos`, `check`, `coverage`, `eval`, `explain`, `contract` and `port` never import,
|
|
176
|
+
execute or `eval` your code: they only parse it with `ast`. Only `verify --level equiv --run-python` and `done UNIT --run-python` run your
|
|
177
|
+
Python, in a child process with best-effort limits (network calls stubbed, memory and time capped; not an OS
|
|
178
|
+
sandbox, so only run it on code you trust), and only when you pass that flag. `cargo` does execute code (build scripts,
|
|
179
|
+
proc-macros), so the MCP server's compiling tools are off unless started with `--allow-compile`.
|
|
180
|
+
|
|
181
|
+
## What it is for
|
|
182
|
+
|
|
183
|
+
python2rust targets real application Python: typed functions, services, tools and worker jobs, with the
|
|
184
|
+
async code, `try`/`except` and library calls that go with them. It was built to port a production backend of
|
|
185
|
+
roughly 100k lines, and the mapping rules come from that port, not from guesses. FastAPI routes are one
|
|
186
|
+
supported profile, not the centre of the tool.
|
|
187
|
+
|
|
188
|
+
<!-- constructs:begin (generated by tools/readme_constructs.py; checked by a test) -->
|
|
189
|
+
180 constructs: **123 supported**, **39 partial** (a subset; the rest is an explicit TODO), **18 explicit TODO** today.
|
|
190
|
+
|
|
191
|
+
| Area | supported | partial | explicit TODO |
|
|
192
|
+
|---|---:|---:|---:|
|
|
193
|
+
| Expressions | 12 | 10 | 2 |
|
|
194
|
+
| Statements | 8 | 11 | 8 |
|
|
195
|
+
| Builtin functions | 27 | 0 | 0 |
|
|
196
|
+
| str / list / dict / set methods | 66 | 0 | 0 |
|
|
197
|
+
| Types | 3 | 0 | 0 |
|
|
198
|
+
| Models (pydantic, dataclass, enum, TypedDict) | 6 | 0 | 1 |
|
|
199
|
+
| Functions | 0 | 3 | 2 |
|
|
200
|
+
| Classes | 0 | 0 | 1 |
|
|
201
|
+
| Exceptions | 0 | 1 | 0 |
|
|
202
|
+
| Async | 1 | 0 | 4 |
|
|
203
|
+
| Modules | 0 | 2 | 0 |
|
|
204
|
+
| Projects (a directory as one crate) | 0 | 1 | 0 |
|
|
205
|
+
| Tests (pytest, unittest, doctest) | 0 | 1 | 0 |
|
|
206
|
+
| Libraries (mapped calls only) | 0 | 10 | 0 |
|
|
207
|
+
|
|
208
|
+
**Explicit TODO today** (stable codes, never silently dropped): `Yield expression`, `YieldFrom expression`, `async for`, `async with`, `asyncio.Lock / Semaphore / Queue`, `asyncio.create_task`, `asyncio.gather`, `asyncio.wait_for / timeout`, `decorators`, `generator function`, `global`, `nested async function`, `nested class`, `nested function`, `nonlocal`, `plain class / methods`, `try/except*`, `validators and computed fields`.
|
|
209
|
+
|
|
210
|
+
**Partial** (the common shapes are translated, the rest is a TODO): `*args / **kwargs parameters`, `Assign statement`, `Attribute expression`, `AugAssign statement`, `Await expression`, `BoolOp expression`, `Call expression`, `Compare expression`, `Delete statement`, `For statement`, `Import statement`, `ImportFrom statement`, `JoinedStr expression`, `Lambda expression`, `Match statement`, `Name expression`, `NamedExpr expression`, `Raise statement`, `Subscript expression`, `Try statement`, `While statement`, `With statement`, `async def / await of coroutines`, `default arguments`, `exception classes (kind tree)`, `import (typing/pydantic/mapped/library)`, `module-level constant`, `multi-module projects`, `pytest / unittest / doctest -> #[test]`; mapped library calls: asyncio, base64, hashlib, html, json, math, re, time, urllib, uuid.
|
|
211
|
+
|
|
212
|
+
Run `python2rust constructs` for the full list with codes. The test suite fails if this block drifts.
|
|
213
|
+
<!-- constructs:end -->
|
|
214
|
+
|
|
215
|
+
Do not expect a large codebase to port with one command. Models and plain logic come out mechanically and are
|
|
216
|
+
checked for compiling **and** producing the same output; the rest is closed task by task by an agent. The status above is
|
|
217
|
+
generated from the translator's own construct list, and `python2rust coverage` reports what your own code gets.
|
|
218
|
+
|
|
219
|
+
## Quickstart
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# once published to PyPI; until then: uvx --from git+https://github.com/bmsuisse/python2rust python2rust ...
|
|
223
|
+
uvx python2rust translate shop.py # Rust on stdout, summary on stderr
|
|
224
|
+
uvx python2rust translate src/ -o rust/ # a directory: rust/**.rs + .todo.json + .diagnostics.json
|
|
225
|
+
uvx python2rust todos src/ -o rust/ --json # the agent work list
|
|
226
|
+
uvx python2rust check rust/ --deps-from Cargo.toml # cargo check in a scratch crate, errors by category
|
|
227
|
+
uvx python2rust explain PY2RS001 # what a diagnostic means and how to fix it
|
|
228
|
+
uvx python2rust coverage src/ # corpus metrics as a markdown table
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
| Command | What it does |
|
|
232
|
+
|---|---|
|
|
233
|
+
| `translate` | Python to Rust, plus diagnostics, source map and tasks |
|
|
234
|
+
| `todos` | the agent hand-off list, one task per `todo!()` |
|
|
235
|
+
| `check` / `verify` | compile the output and map errors to Python lines; `verify` climbs a ladder of checks |
|
|
236
|
+
| `apply` | store an agent's fix for a task, behind an anti-cheat gate |
|
|
237
|
+
| `port` | the one-command loop: translate, compile, repair (dry run unless `--agent` is set) |
|
|
238
|
+
| `contract` | diff a Python OpenAPI document against the Rust one (experimental) |
|
|
239
|
+
| `eval` / `coverage` | metrics over a corpus |
|
|
240
|
+
| `explain` / `constructs` / `schema` | documentation for diagnostics, supported constructs and JSON output |
|
|
241
|
+
| `mcp` / `skill` / `doctor` | MCP server, the bundled agent skill, environment check |
|
|
242
|
+
|
|
243
|
+
`python2rust` and `py2rust` are the same program. It needs Python 3.14 or newer; `rustfmt` and `cargo` are needed
|
|
244
|
+
only for formatting and `check` (`python2rust doctor` reports what is available).
|
|
245
|
+
|
|
246
|
+
## Use it with an agent
|
|
247
|
+
|
|
248
|
+
`python2rust skill` prints a ready-to-use agent skill with the exact JSON contracts, and [AGENTS.md](AGENTS.md)
|
|
249
|
+
holds the rules (never edit generated files blindly, always verify, escalate review items). For MCP clients:
|
|
250
|
+
`pip install 'python2rust[mcp]'`, then register `python2rust mcp` (stdio). The tools are `translate_source`,
|
|
251
|
+
`list_todos`, `explain_diagnostic`, `check_rust`, `coverage`, `apply_patch` and the workflow tools, each returning the
|
|
252
|
+
same JSON as the CLI. Files the tools read are limited to `--root` (default: the working directory). The tools that
|
|
253
|
+
run cargo (`check_rust`, `apply_patch`, coverage levels check and above) are off unless the server is started with
|
|
254
|
+
`--allow-compile`: cargo executes code, and these tools compile Rust that a model supplied. That compile runs in an OS
|
|
255
|
+
sandbox (no network, file reads confined to the scratch crate, the cargo/rustup homes and the toolchain): `sandbox-exec`
|
|
256
|
+
on macOS, `bwrap` on Linux. Without one the server refuses to compile unless it is started with
|
|
257
|
+
`--allow-unsandboxed-compile`.
|
|
258
|
+
|
|
259
|
+
<details>
|
|
260
|
+
<summary><b>Start a port: a prompt to give your agent</b></summary>
|
|
261
|
+
|
|
262
|
+
Paste this into Claude Code, Codex or any coding agent that can run shell commands. Replace the three values in
|
|
263
|
+
angle brackets first.
|
|
264
|
+
|
|
265
|
+
````text
|
|
266
|
+
You are porting a typed Python codebase to Rust with python2rust. Work in small, checked steps.
|
|
267
|
+
|
|
268
|
+
Setup
|
|
269
|
+
- Python source: <path/to/python/src>. Rust target crate: <path/to/rust/crate> (create it with
|
|
270
|
+
`cargo new --lib` if missing; add the dependencies python2rust reports as unresolved).
|
|
271
|
+
- Run `uvx python2rust doctor --json` and `uvx python2rust skill` first. Read the skill: it has the exact
|
|
272
|
+
JSON contracts. Never guess a command; `uvx python2rust --help` lists them.
|
|
273
|
+
|
|
274
|
+
Plan
|
|
275
|
+
1. Measure: `uvx python2rust coverage <python src> --json`. Pick the smallest module with the highest share
|
|
276
|
+
of clean functions. Port in this order: models and enums, pure functions, async services, HTTP routes.
|
|
277
|
+
2. Translate one module: `uvx python2rust translate <module.py> -o <rust crate>/src/ --json`.
|
|
278
|
+
3. List the work: `uvx python2rust todos <module.py> -o <rust crate>/src/ --json`. Each item has the Python
|
|
279
|
+
snippet, the Rust context and an instruction.
|
|
280
|
+
4. Fix every `todo!()` from its snippet and submit the fix with `uvx python2rust apply <TODO_ID> --patch FILE`
|
|
281
|
+
(or `-` for stdin). NEVER edit the generated files: `apply` stores the fix and every re-translate puts it back, so
|
|
282
|
+
re-translating is always safe. Keep behaviour identical to the Python (error cases, defaults, order of checks).
|
|
283
|
+
`apply` accepts a fix only if it compiles, every translated test that uses the module passes (tests are never
|
|
284
|
+
fixed: a TODO inside a test is refused) and, for a pure function with a JSON-able signature, the output equals
|
|
285
|
+
the Python's: that needs `--run-python` (the Python runs in a best-effort-limited child process, not an OS sandbox: ask your human first); without it the
|
|
286
|
+
fix is stored as `unverified`. `--no-equiv` opts out and is recorded as "check+tests, not equivalence".
|
|
287
|
+
Or let `uvx python2rust port <python src> -o <rust crate>` do the loop (add `--agent` to let it call a model).
|
|
288
|
+
5. Verify: `uvx python2rust check <rust crate>/src/ --deps-from <rust crate>/Cargo.toml --json`, then
|
|
289
|
+
`cargo test`. Fix by category until both pass. `apply` rejects `todo!`, `unwrap`, `expect`, `panic!`,
|
|
290
|
+
`#[allow]`, `Default::default()` stand-ins and `unsafe`: do not try to get around that, and never edit or delete a
|
|
291
|
+
test to make the Rust pass.
|
|
292
|
+
6. Port the Python tests for the module and make them pass against the Rust code.
|
|
293
|
+
7. Commit one module at a time, then repeat from step 1.
|
|
294
|
+
|
|
295
|
+
Rules
|
|
296
|
+
- Items marked `needs_review: true` (auth, tokens, SQL writes, outbound HTTP, crypto, permissions) must be
|
|
297
|
+
listed in your final report for a human to review. Do not mark them done yourself.
|
|
298
|
+
- If python2rust emits a wrong translation (not just a TODO), do not hand-patch it quietly: write the
|
|
299
|
+
Python snippet, the wrong Rust and the correct Rust into `PYTHON2RUST_FEEDBACK.md` so the tool can be
|
|
300
|
+
fixed.
|
|
301
|
+
- Never delete the Python original until the Rust version passes the ported tests.
|
|
302
|
+
- Stop and ask when the Python behaviour is unclear or relies on dynamic features (`getattr`, `**kwargs`
|
|
303
|
+
forwarding, monkeypatching).
|
|
304
|
+
|
|
305
|
+
Report at the end: modules ported, tests passing, the review list, the feedback file, and what is left.
|
|
306
|
+
````
|
|
307
|
+
|
|
308
|
+
For a web framework port (FastAPI to Axum), add: "Port routes after their models, keep every status code, path
|
|
309
|
+
and response model, and compare the generated OpenAPI with the original."
|
|
310
|
+
|
|
311
|
+
</details>
|
|
312
|
+
|
|
313
|
+
<details>
|
|
314
|
+
<summary><b>Exit codes and JSON output</b></summary>
|
|
315
|
+
|
|
316
|
+
Every command takes `--json`: stdout is then exactly one JSON document and human text goes to stderr (`--quiet`
|
|
317
|
+
silences it). Nothing is ever interactive; `-` reads stdin; output order is stable.
|
|
318
|
+
|
|
319
|
+
| code | meaning |
|
|
320
|
+
|---|---|
|
|
321
|
+
| 0 | ok: no TODOs, no error diagnostics (`check`: it compiles) |
|
|
322
|
+
| 1 | translated, but TODOs or error diagnostics remain, or the result could not be verified (for example no cargo) |
|
|
323
|
+
| 2 | usage error (bad flag, missing path, invalid config) |
|
|
324
|
+
| 3 | internal error, or a missing core or optional dependency |
|
|
325
|
+
| 4 | the Rust does not compile or verify: compile errors, a failing rung (clippy, test, equiv), a rejected fix |
|
|
326
|
+
|
|
327
|
+
`python2rust schema [translate|todos|coverage|check|...]` prints the JSON Schema of each output.
|
|
328
|
+
|
|
329
|
+
```jsonc
|
|
330
|
+
// python2rust translate shop.py --json (abridged)
|
|
331
|
+
{"schema_version": 1, "command": "translate", "ok": false,
|
|
332
|
+
"summary": {"files": 1, "files_clean": 0, "files_with_todos": 1, "todo_count": 1, "...": "..."},
|
|
333
|
+
"files": [{"file": "shop.py", "status": "todo", "rust_path": null, "rust": "pub fn add(...) ...",
|
|
334
|
+
"stats": {"functions_total": 2, "functions_clean": 1, "models_total": 0, "models_clean": 0, "todo_count": 1},
|
|
335
|
+
"diagnostics": [{"code": "PY2RS005", "severity": "warning", "file": "shop.py", "line": 6, "col": 0,
|
|
336
|
+
"construct": "function-body", "message": "...", "hint": "..."}],
|
|
337
|
+
"todos": ["..."]}]}
|
|
338
|
+
|
|
339
|
+
// python2rust todos shop.py -o out --json (the agent hand-off contract, abridged)
|
|
340
|
+
{"count": 1, "todos": [{
|
|
341
|
+
"id": "t3f9a1c2e", "code": "PY2RS005", "kind": "function-body", "file": "shop.py", "line": 6,
|
|
342
|
+
"python_snippet": "def get(o, name: str):\n return getattr(o, name)",
|
|
343
|
+
"rust_context": "pub fn get(o: (), name: String) -> () {", "rust_line": 8, "rust_file": "out/shop.rs",
|
|
344
|
+
"needs_review": false, "review_reason": null,
|
|
345
|
+
"instruction": "Replace the todo!() for t3f9a1c2e ... at out/shop.rs:8 with Rust that does what the Python at shop.py:6 does. ..."}]}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
Task ids are stable content hashes (`t` plus eight hex digits, like `t3f9a1c2e`); `python2rust schema` is the
|
|
349
|
+
contract to rely on for the exact fields.
|
|
350
|
+
|
|
351
|
+
</details>
|
|
352
|
+
|
|
353
|
+
## Configuration
|
|
354
|
+
|
|
355
|
+
`--config project.toml` carries what the translator cannot guess about your project: `import_map` (Python module to
|
|
356
|
+
Rust path), `library_map` (third-party call to crate API), `type_map` and `review_patterns` (what to flag for
|
|
357
|
+
review). Keep it outside the generated output and re-translate after changing it.
|
|
358
|
+
|
|
359
|
+
## python2rust and py2many
|
|
360
|
+
|
|
361
|
+
[py2many](https://github.com/py2many/py2many) (MIT) is the established Python transpiler and a major influence
|
|
362
|
+
here. Choose it when you want **many target languages** (C++, Go, Kotlin, Julia, Dart, Nim, V, Zig, Rust and more)
|
|
363
|
+
from one tool, when your Python is small, self-contained and often **unannotated** (it infers types), or when you
|
|
364
|
+
want a mature project with years of testing. Its Rust backend is its most developed one.
|
|
365
|
+
|
|
366
|
+
python2rust makes different trade-offs, aimed at porting large, *typed* application code with an agent in the loop:
|
|
367
|
+
|
|
368
|
+
| | py2many | python2rust |
|
|
369
|
+
|---|---|---|
|
|
370
|
+
| Targets | many languages | Rust only |
|
|
371
|
+
| Input | Python with type inference, wide version range | annotated Python, 3.14 syntax |
|
|
372
|
+
| Middle layer | rewrites and inference on the Python AST, code emitted per language | a typed IR between Python and a Rust emitter |
|
|
373
|
+
| Unsupported code | may raise, or be approximated depending on the node | always a `todo!()` plus a diagnostic |
|
|
374
|
+
| Output for tools | formatted source | source, diagnostics JSON, per-file task list, stable codes, JSON Schemas |
|
|
375
|
+
| Validation | none built in | compiles the output and maps errors back to Python lines |
|
|
376
|
+
| Interface | CLI | CLI with `--json` everywhere, MCP server, bundled agent skill |
|
|
377
|
+
|
|
378
|
+
The difference we care about most is a policy. In our own experiments on an annotated, async-heavy codebase,
|
|
379
|
+
`async`/`await`, `try`/`except`, dict comprehensions and walrus assignments were unsupported in py2many 0.9 (or
|
|
380
|
+
produced Rust that did not parse), and some constructs such as `**kwargs` were dropped without a diagnostic.
|
|
381
|
+
python2rust treats an untranslated construct as data an agent can act on. That is a design choice for this use
|
|
382
|
+
case, not a verdict on py2many; versions change, so measure on your own code. [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)
|
|
383
|
+
describes what we took from it.
|
|
384
|
+
|
|
385
|
+
## Development
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
uv sync # installs the dev tools
|
|
389
|
+
uv run pytest # CLI contract tests, MCP in-memory tests, cargo tests (skipped without cargo)
|
|
390
|
+
uv run ruff check && uv run ruff format --check && uv run ty check
|
|
391
|
+
uv build
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Contributions are welcome. Read [AGENTS.md](AGENTS.md) first; this is a public project, so examples and tests use
|
|
395
|
+
only synthetic code. Licensed under the [MIT License](LICENSE).
|