├── pylib ├── Lib └── Cargo.toml ├── Lib ├── urllib │ └── __init__.py ├── __phello__ │ ├── ham │ │ ├── eggs.py │ │ └── __init__.py │ ├── spam.py │ └── __init__.py ├── email │ └── mime │ │ └── __init__.py ├── pydoc_data │ ├── __init__.py │ └── _pydoc.css ├── test │ ├── test_import │ │ ├── data │ │ │ ├── unwritable │ │ │ │ ├── x.py │ │ │ │ └── __init__.py │ │ │ ├── package │ │ │ │ ├── submodule.py │ │ │ │ └── __init__.py │ │ │ ├── package2 │ │ │ │ ├── submodule2.py │ │ │ │ └── submodule1.py │ │ │ └── circular_imports │ │ │ │ ├── subpkg2 │ │ │ │ ├── __init__.py │ │ │ │ └── parent │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── child.py │ │ │ │ ├── basic2.py │ │ │ │ ├── util.py │ │ │ │ ├── indirect.py │ │ │ │ ├── source.py │ │ │ │ ├── subpkg │ │ │ │ ├── util.py │ │ │ │ └── subpackage2.py │ │ │ │ ├── use.py │ │ │ │ ├── from_cycle1.py │ │ │ │ ├── from_cycle2.py │ │ │ │ ├── binding2.py │ │ │ │ ├── binding.py │ │ │ │ ├── basic.py │ │ │ │ ├── rebinding2.py │ │ │ │ ├── subpackage.py │ │ │ │ └── rebinding.py │ │ └── __main__.py │ ├── test_importlib │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── example-21.12-py3.6.egg │ │ │ ├── example-21.12-py3-none-any.whl │ │ │ └── example2-1.0.0-py3-none-any.whl │ │ ├── data01 │ │ │ ├── __init__.py │ │ │ ├── binary.file │ │ │ ├── subdirectory │ │ │ │ ├── __init__.py │ │ │ │ └── binary.file │ │ │ ├── utf-8.file │ │ │ └── utf-16.file │ │ ├── data02 │ │ │ ├── __init__.py │ │ │ ├── one │ │ │ │ ├── __init__.py │ │ │ │ └── resource1.txt │ │ │ └── two │ │ │ │ ├── __init__.py │ │ │ │ └── resource2.txt │ │ ├── data03 │ │ │ ├── __init__.py │ │ │ └── namespace │ │ │ │ ├── resource1.txt │ │ │ │ ├── portion1 │ │ │ │ └── __init__.py │ │ │ │ └── portion2 │ │ │ │ └── __init__.py │ │ ├── resources │ │ │ └── __init__.py │ │ ├── zipdata01 │ │ │ ├── __init__.py │ │ │ └── ziptestdata.zip │ │ ├── zipdata02 │ │ │ ├── __init__.py │ │ │ └── ziptestdata.zip │ │ ├── namespacedata01 │ │ │ ├── binary.file │ │ │ ├── utf-8.file │ │ │ └── utf-16.file │ │ ├── namespace_pkgs │ │ │ ├── not_a_namespace_pkg │ │ │ │ └── foo │ │ │ │ │ ├── __init__.py │ │ │ │ │ └── one.py │ │ │ ├── module_and_namespace_package │ │ │ │ ├── a_test │ │ │ │ │ └── empty │ │ │ │ └── a_test.py │ │ │ ├── portion1 │ │ │ │ └── foo │ │ │ │ │ └── one.py │ │ │ ├── portion2 │ │ │ │ └── foo │ │ │ │ │ └── two.py │ │ │ ├── both_portions │ │ │ │ └── foo │ │ │ │ │ ├── one.py │ │ │ │ │ └── two.py │ │ │ ├── project1 │ │ │ │ └── parent │ │ │ │ │ └── child │ │ │ │ │ └── one.py │ │ │ ├── project2 │ │ │ │ └── parent │ │ │ │ │ └── child │ │ │ │ │ └── two.py │ │ │ ├── project3 │ │ │ │ └── parent │ │ │ │ │ └── child │ │ │ │ │ └── three.py │ │ │ ├── nested_portion1.zip │ │ │ ├── missing_directory.zip │ │ │ └── top_level_portion1.zip │ │ ├── __main__.py │ │ ├── builtin │ │ │ ├── __main__.py │ │ │ └── __init__.py │ │ ├── frozen │ │ │ ├── __main__.py │ │ │ └── __init__.py │ │ ├── import_ │ │ │ ├── __main__.py │ │ │ └── __init__.py │ │ ├── source │ │ │ ├── __main__.py │ │ │ └── __init__.py │ │ ├── extension │ │ │ ├── __main__.py │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── stubs.py │ │ └── partial │ │ │ └── pool_in_threads.py │ ├── xmltestdata │ │ ├── c14n-20 │ │ │ ├── world.txt │ │ │ ├── out_inC14N6_c14nDefault.xml │ │ │ ├── out_inC14N5_c14nTrim.xml │ │ │ ├── inC14N6.xml │ │ │ ├── out_inC14N5_c14nDefault.xml │ │ │ ├── doc.dtd │ │ │ ├── inNsDefault.xml │ │ │ ├── out_inNsDefault_c14nDefault.xml │ │ │ ├── out_inC14N2_c14nTrim.xml │ │ │ ├── out_inNsDefault_c14nPrefix.xml │ │ │ ├── out_inC14N1_c14nDefault.xml │ │ │ ├── inNsPushdown.xml │ │ │ ├── out_inNsSuperfluous_c14nPrefix.xml │ │ │ ├── out_inNsXml_c14nDefault.xml │ │ │ ├── c14nDefault.xml │ │ │ ├── doc.xsl │ │ │ ├── out_inNsXml_c14nPrefix.xml │ │ │ ├── inNsRedecl.xml │ │ │ ├── inNsSort.xml │ │ │ ├── out_inC14N1_c14nComment.xml │ │ │ ├── inNsXml.xml │ │ │ ├── out_inNsRedecl_c14nPrefix.xml │ │ │ ├── out_inNsXml_c14nQname.xml │ │ │ ├── out_inNsRedecl_c14nDefault.xml │ │ │ ├── inNsSuperfluous.xml │ │ │ ├── out_inNsSort_c14nDefault.xml │ │ │ ├── out_inNsSuperfluous_c14nDefault.xml │ │ │ ├── out_inNsXml_c14nPrefixQname.xml │ │ │ ├── inC14N2.xml │ │ │ ├── out_inNsSort_c14nPrefix.xml │ │ │ ├── out_inNsPushdown_c14nDefault.xml │ │ │ ├── out_inC14N2_c14nDefault.xml │ │ │ ├── out_inNsPushdown_c14nPrefix.xml │ │ │ ├── out_inNsContent_c14nDefault.xml │ │ │ ├── c14nTrim.xml │ │ │ ├── c14nComment.xml │ │ │ ├── c14nPrefix.xml │ │ │ ├── inC14N1.xml │ │ │ ├── out_inNsContent_c14nQnameElem.xml │ │ │ ├── c14nQnameElem.xml │ │ │ ├── out_inC14N3_c14nTrim.xml │ │ │ ├── c14nQname.xml │ │ │ ├── out_inNsContent_c14nPrefixQnameXpathElem.xml │ │ │ ├── inC14N5.xml │ │ │ ├── out_inNsContent_c14nQnameXpathElem.xml │ │ │ ├── inNsContent.xml │ │ │ ├── c14nQnameXpathElem.xml │ │ │ ├── c14nPrefixQname.xml │ │ │ ├── out_inC14N4_c14nTrim.xml │ │ │ ├── c14nPrefixQnameXpathElem.xml │ │ │ ├── out_inC14N3_c14nDefault.xml │ │ │ ├── out_inC14N4_c14nDefault.xml │ │ │ ├── out_inC14N3_c14nPrefix.xml │ │ │ ├── inC14N4.xml │ │ │ └── inC14N3.xml │ │ ├── test.xml │ │ ├── test.xml.out │ │ ├── simple.xml │ │ ├── simple-ns.xml │ │ └── expat224_utf8_bug.xml │ ├── relimport.py │ ├── test_tomllib │ │ ├── data │ │ │ ├── valid │ │ │ │ ├── no-newlines.json │ │ │ │ ├── trailing-comma.toml │ │ │ │ ├── boolean.toml │ │ │ │ ├── empty-inline-table.json │ │ │ │ ├── no-newlines.toml │ │ │ │ ├── dates-and-times │ │ │ │ │ ├── localtime.toml │ │ │ │ │ ├── localtime.json │ │ │ │ │ ├── datetimes.toml │ │ │ │ │ └── datetimes.json │ │ │ │ ├── hex-char.toml │ │ │ │ ├── empty-inline-table.toml │ │ │ │ ├── array │ │ │ │ │ ├── array-subtables.toml │ │ │ │ │ ├── open-parent-table.toml │ │ │ │ │ ├── open-parent-table.json │ │ │ │ │ └── array-subtables.json │ │ │ │ ├── boolean.json │ │ │ │ ├── multiline-basic-str │ │ │ │ │ ├── ends-in-whitespace-escape.json │ │ │ │ │ └── ends-in-whitespace-escape.toml │ │ │ │ ├── apostrophes-in-literal-string.toml │ │ │ │ ├── apostrophes-in-literal-string.json │ │ │ │ ├── five-quotes.toml │ │ │ │ ├── trailing-comma.json │ │ │ │ ├── hex-char.json │ │ │ │ └── five-quotes.json │ │ │ └── invalid │ │ │ │ ├── array │ │ │ │ ├── unclosed-empty.toml │ │ │ │ ├── file-end-after-val.toml │ │ │ │ └── unclosed-after-item.toml │ │ │ │ ├── non-scalar-escaped.toml │ │ │ │ ├── table │ │ │ │ ├── eof-after-opening.toml │ │ │ │ ├── redefine-1.toml │ │ │ │ └── redefine-2.toml │ │ │ │ ├── inline-table │ │ │ │ ├── unclosed-empty.toml │ │ │ │ ├── file-end-after-key-val.toml │ │ │ │ ├── mutate.toml │ │ │ │ ├── define-twice.toml │ │ │ │ ├── overwrite-implicitly.toml │ │ │ │ ├── define-twice-in-subtable.toml │ │ │ │ ├── override-val-with-array.toml │ │ │ │ ├── override-val-with-table.toml │ │ │ │ ├── overwrite-value-in-inner-array.toml │ │ │ │ ├── overwrite-value-in-inner-table.toml │ │ │ │ └── override-val-in-table.toml │ │ │ │ ├── invalid-hex.toml │ │ │ │ ├── keys-and-vals │ │ │ │ ├── ends-early.toml │ │ │ │ ├── no-value.toml │ │ │ │ ├── only-ws-after-dot.toml │ │ │ │ ├── ends-early-table-def.toml │ │ │ │ └── overwrite-with-deep-table.toml │ │ │ │ ├── boolean │ │ │ │ ├── invalid-false-casing.toml │ │ │ │ └── invalid-true-casing.toml │ │ │ │ ├── literal-str │ │ │ │ └── unclosed.toml │ │ │ │ ├── array-missing-comma.toml │ │ │ │ ├── unclosed-string.toml │ │ │ │ ├── multiline-basic-str │ │ │ │ ├── file-ends-after-opening.toml │ │ │ │ ├── escape-only.toml │ │ │ │ ├── last-line-escape.toml │ │ │ │ ├── unclosed-ends-in-whitespace-escape.toml │ │ │ │ └── carriage-return.toml │ │ │ │ ├── basic-str-ends-in-escape.toml │ │ │ │ ├── dotted-keys │ │ │ │ ├── access-non-table.toml │ │ │ │ ├── extend-defined-aot.toml │ │ │ │ ├── extend-defined-table.toml │ │ │ │ └── extend-defined-table-with-subtable.toml │ │ │ │ ├── multiline-literal-str │ │ │ │ ├── file-ends-after-opening.toml │ │ │ │ └── unclosed.toml │ │ │ │ ├── array-of-tables │ │ │ │ ├── overwrite-bool-with-aot.toml │ │ │ │ └── overwrite-array-in-parent.toml │ │ │ │ ├── invalid-escaped-unicode.toml │ │ │ │ ├── invalid-comment-char.toml │ │ │ │ ├── missing-closing-square-bracket.toml │ │ │ │ ├── dates-and-times │ │ │ │ └── invalid-day.toml │ │ │ │ ├── inline-table-missing-comma.toml │ │ │ │ ├── missing-closing-double-square-bracket.toml │ │ │ │ └── unclosed-multiline-string.toml │ │ ├── __main__.py │ │ └── __init__.py │ ├── badsyntax_3131.py │ ├── __init__.py │ ├── __main__.py │ ├── testtar.tar │ ├── zipdir.zip │ ├── cfgparser.1 │ ├── badsyntax_pep3120.py │ ├── test_json │ │ ├── __main__.py │ │ ├── test_default.py │ │ ├── test_pass2.py │ │ └── test_pass3.py │ ├── zip_cp437_header.zip │ ├── ziptestdata │ │ ├── exe_with_z64 │ │ ├── exe_with_zip │ │ └── testdata_module_inside_zip.py │ ├── ann_module4.py │ ├── badsyntax_future10.py │ ├── encoded_modules │ │ ├── module_koi8_r.py │ │ └── module_iso_8859_1.py │ ├── test_sqlite3 │ │ ├── __main__.py │ │ └── __init__.py │ ├── ann_module6.py │ ├── subprocessdata │ │ ├── input_reader.py │ │ ├── qcat.py │ │ └── qgrep.py │ ├── badsyntax_future8.py │ ├── dataclass_textanno.py │ ├── badsyntax_future9.py │ ├── tracedmodules │ │ ├── testmod.py │ │ └── __init__.py │ ├── future_test2.py │ ├── badsyntax_future4.py │ ├── badsyntax_future6.py │ ├── libregrtest │ │ └── __init__.py │ ├── badsyntax_future3.py │ ├── test_ctypes.py │ ├── ann_module5.py │ ├── badsyntax_future5.py │ ├── badsyntax_future7.py │ ├── test_future4.py │ ├── test_longexp.py │ ├── future_test1.py │ ├── test_unittest.py │ ├── ann_module7.py │ ├── tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt │ ├── tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt │ ├── recursion.tar │ ├── tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt │ ├── ann_module3.py │ ├── tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt │ ├── _typed_dict_helper.py │ ├── xmltests.py │ ├── test_future5.py │ ├── test_future3.py │ ├── test_eintr.py │ └── ann_module2.py ├── concurrent │ └── __init__.py ├── xmlrpc │ └── __init__.py ├── unittest │ ├── test │ │ ├── dummy.py │ │ ├── testmock │ │ │ ├── support.py │ │ │ └── __init__.py │ │ └── __main__.py │ └── __main__.py ├── ctypes │ ├── test │ │ ├── __main__.py │ │ ├── __init__.py │ │ └── test_delattr.py │ └── macholib │ │ ├── fetch_macholib.bat │ │ ├── fetch_macholib │ │ ├── __init__.py │ │ └── README.ctypes ├── xml │ ├── etree │ │ └── cElementTree.py │ ├── parsers │ │ ├── __init__.py │ │ └── expat.py │ └── __init__.py ├── ensurepip │ ├── __main__.py │ └── _bundled │ │ ├── pip-22.3.1-py3-none-any.whl │ │ └── setuptools-65.5.0-py3-none-any.whl ├── collections │ └── abc.py ├── contextvars.py ├── asyncio │ ├── log.py │ ├── constants.py │ └── compat.py ├── distutils │ ├── debug.py │ ├── __init__.py │ └── README ├── venv │ ├── __main__.py │ └── scripts │ │ └── nt │ │ └── deactivate.bat ├── __hello__.py ├── tomllib │ ├── _types.py │ └── __init__.py ├── struct.py ├── decimal.py ├── importlib │ ├── readers.py │ ├── simple.py │ └── resources │ │ └── __init__.py ├── dis.py ├── antigravity.py ├── README.md └── wsgiref │ └── __init__.py ├── rustfmt.toml ├── wasm ├── demo │ ├── src │ │ ├── browser_module.rs │ │ └── style.css │ └── snippets │ │ ├── fizzbuzz.py │ │ ├── fibonacci.py │ │ ├── fetch.py │ │ └── asyncbrowser.py ├── tests │ ├── .gitignore │ ├── requirements.txt │ ├── test_inject_module.py │ └── test_demo.py ├── .gitignore ├── .prettierrc ├── notebook │ └── screenshot.png └── example │ ├── src │ ├── main.js │ ├── index.js │ └── main.py │ ├── webpack.config.js │ ├── index.html │ └── package.json ├── extra_tests ├── requirements.txt ├── snippets │ ├── dir_module │ │ ├── relative.py │ │ ├── __init__.py │ │ └── dir_module_inner │ │ │ └── __init__.py │ ├── dir_main │ │ └── __main__.py │ ├── intro │ │ ├── 3.1.2.3.py │ │ ├── 3.1.2.6.py │ │ ├── 3.1.2.5.py │ │ ├── 3.1.1.6.py │ │ ├── 3.1.1.3.py │ │ ├── 3.1.1.4.py │ │ ├── 3.1.2.4.py │ │ ├── 3.1.1.1.py │ │ ├── 3.1.2.10.py │ │ ├── 3.1.2.1.py │ │ └── 3.1.1.2.py │ ├── xfail_assert.py │ ├── 3.1.2.19.py │ ├── 3.1.3.5.py │ ├── 3.1.3.4.py │ ├── builtin_len.py │ ├── frozen.py │ ├── scope_lambda.py │ ├── stdlib_warnings.py │ ├── import_mutual2.py │ ├── import_name.py │ ├── import_mutual1.py │ ├── 3.1.2.16.py │ ├── builtin_thread.py │ ├── 3.1.2.18.py │ ├── syntax_decimal.py │ ├── builtin_eval.py │ ├── import_file.py │ ├── import_star.py │ ├── imghdrdata │ │ ├── python.bmp │ │ ├── python.exr │ │ ├── python.gif │ │ ├── python.jpg │ │ ├── python.pbm │ │ ├── python.pgm │ │ ├── python.png │ │ ├── python.ppm │ │ ├── python.ras │ │ ├── python.sgi │ │ ├── python.tiff │ │ ├── python.webp │ │ └── python.xbm │ ├── builtin_abs.py │ ├── builtin_reversed.py │ ├── builtin_file.py │ ├── syntax_statement.py │ ├── non_utf8.txt │ ├── syntax_call_nested.py │ ├── builtin_hex.py │ ├── syntax_if.py │ ├── import_target.py │ ├── stdlib_operator.py │ ├── syntax_comma.py │ ├── syntax_while.py │ ├── stdlib_types.py │ ├── syntax_comment.py │ ├── syntax_literal.py │ ├── name.py │ ├── stdlib_xdrlib.py │ ├── builtin_locals.py │ ├── stdlib_logging.py │ ├── syntax_non_utf8.py │ ├── syntax_indent.py │ ├── builtin_chr.py │ ├── protocol_iternext.py │ ├── example_fizzbuzz.py │ ├── recursion.py │ ├── builtin_ascii.py │ ├── builtin_all.py │ ├── protocol_callable.py │ ├── builtin_any.py │ ├── syntax_short_circuit_evaluations.py │ ├── builtin_divmod.py │ ├── stdlib_termios.py │ ├── builtin_type_mro.py │ ├── syntax_type_hint.py │ ├── 3.1.2.13.py │ ├── stdlib_weakref.py │ ├── builtin_super.py │ ├── syntax_for.py │ ├── builtin_bin.py │ ├── stdlib_time.py │ ├── syntax_funky.py │ ├── builtin_hash.py │ ├── jit.py │ ├── builtin_none.py │ ├── builtin_print.py │ ├── operator_cast.py │ ├── stdlib_sys_getframe.py │ ├── syntax_decorator.py │ ├── builtin_mappingproxy.py │ ├── builtin_str_encode.py │ ├── index_overflow.py │ ├── stdlib_traceback.py │ ├── code_co_consts.py │ ├── builtin_callable.py │ ├── builtin_open.py │ ├── builtin_ord.py │ ├── test_threading.py │ ├── builtin_str_subclass.py │ └── syntax_del.py ├── .gitignore └── benchmarks │ ├── perf_add.py │ └── perf_fib.py ├── vm ├── Lib │ ├── core_modules │ │ ├── codecs.py │ │ ├── copyreg.py │ │ └── encodings_utf_8.py │ ├── python_builtins │ │ ├── __phello__ │ │ ├── __hello__.py │ │ ├── _thread.py │ │ ├── _frozen_importlib.py │ │ └── _frozen_importlib_external.py │ └── README.md ├── .gitignore └── src │ ├── types │ └── mod.rs │ ├── prelude.rs │ ├── object │ └── mod.rs │ ├── convert │ ├── into_object.rs │ └── mod.rs │ └── protocol │ └── mod.rs ├── rust-toolchain.toml ├── benches ├── microbenchmarks │ ├── define_class.py │ ├── define_function.py │ ├── comprehension_list.py │ ├── comprehension_set.py │ ├── comprehension_dict.py │ ├── addition.py │ ├── construct_object.py │ ├── call_simple.py │ ├── list_count_builtins.py │ ├── strings.py │ ├── call_kwargs.py │ ├── exception_simple.py │ ├── loop_append.py │ ├── loop_string.py │ ├── list_count_custom_eq.py │ ├── cmp.py │ ├── exception_nested.py │ ├── complex_class.py │ └── exception_context.py └── benchmarks │ └── mandelbrot.py ├── .flake8 ├── logo.png ├── examples ├── freeze │ └── freeze.py ├── atexit_example.py ├── package_embed.py ├── call_between_rust_and_python.py └── hello_embed.rs ├── src └── main.rs ├── compiler ├── parser │ └── src │ │ ├── python.rs │ │ └── snapshots │ │ ├── rustpython_parser__parser__tests__parse_empty.snap │ │ ├── rustpython_parser__string__tests__parse_empty_fstring.snap │ │ ├── rustpython_parser__string__tests__parse_fstring_yield_expr.snap │ │ ├── rustpython_parser__context__tests__del_name.snap │ │ ├── rustpython_parser__string__tests__bell_alias.snap │ │ ├── rustpython_parser__string__tests__hts_alias.snap │ │ ├── rustpython_parser__string__tests__backspace_alias.snap │ │ ├── rustpython_parser__string__tests__delete_alias.snap │ │ ├── rustpython_parser__string__tests__escape_alias.snap │ │ ├── rustpython_parser__string__tests__form_feed_alias.snap │ │ ├── rustpython_parser__parser__tests__parse_string.snap │ │ ├── rustpython_parser__string__tests__carriage_return_alias.snap │ │ ├── rustpython_parser__string__tests__parse_string_concat.snap │ │ ├── rustpython_parser__string__tests__parse_u_string_concat_1.snap │ │ ├── rustpython_parser__string__tests__character_tabulation_with_justification_alias.snap │ │ ├── rustpython_parser__string__tests__parse_u_string_concat_2.snap │ │ └── rustpython_parser__string__tests__parse_string_triple_quotes_with_kind.snap ├── ast │ ├── src │ │ └── lib.rs │ └── Cargo.toml ├── Cargo.toml ├── core │ ├── src │ │ └── lib.rs │ └── Cargo.toml └── codegen │ └── src │ ├── snapshots │ ├── rustpython_codegen__compile__tests__if_ors.snap │ ├── rustpython_compiler_core__compile__tests__if_ors.snap │ ├── rustpython_codegen__compile__tests__if_ands.snap │ ├── rustpython_compiler_core__compile__tests__if_ands.snap │ ├── rustpython_compiler_core__compile__tests__if_mixed.snap │ └── rustpython_codegen__compile__tests__if_mixed.snap │ └── lib.rs ├── .gitpod.yml ├── jit └── tests │ ├── lib.rs │ └── none_tests.rs ├── .theia ├── settings.json └── launch.json ├── .devcontainer └── devcontainer.json ├── demo_closures.py ├── ruff_text_size ├── tests │ ├── indexing.rs │ ├── constructors.rs │ └── auto_traits.rs └── Cargo.toml ├── .cargo └── config.toml ├── scripts ├── update_asdl.sh ├── redox │ ├── comment-cargo.sh │ ├── uncomment-cargo.sh │ ├── recipe.sh │ └── run-redoxer.sh ├── release-wapm.sh ├── codecoverage-rustc-wrapper.sh └── install-openssl.ps1 ├── .mailmap ├── .dockerignore ├── .gitignore ├── Dockerfile.bin ├── stdlib └── src │ ├── md5.rs │ ├── sha1.rs │ ├── sha256.rs │ └── blake2.rs ├── .gitattributes ├── common └── src │ ├── rc.rs │ └── char.rs ├── wapm.toml ├── .vscode └── tasks.json ├── derive └── Cargo.toml ├── .github └── ISSUE_TEMPLATE │ ├── report-incompatibility.md │ └── rfc.md ├── derive-impl ├── src │ └── pypayload.rs └── Cargo.toml └── .gitpod.Dockerfile /pylib/Lib: -------------------------------------------------------------------------------- 1 | ../Lib -------------------------------------------------------------------------------- /Lib/urllib/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/__phello__/ham/eggs.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/email/mime/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/pydoc_data/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/__phello__/ham/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2021" 2 | -------------------------------------------------------------------------------- /wasm/demo/src/browser_module.rs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/unwritable/x.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data01/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data02/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data03/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/world.txt: -------------------------------------------------------------------------------- 1 | world -------------------------------------------------------------------------------- /Lib/test/test_import/data/package/submodule.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/package2/submodule2.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data01/binary.file: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Lib/test/test_importlib/data02/one/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data02/two/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/resources/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/zipdata01/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/zipdata02/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/relimport.py: -------------------------------------------------------------------------------- 1 | from .test_import import * 2 | -------------------------------------------------------------------------------- /extra_tests/requirements.txt: -------------------------------------------------------------------------------- 1 | bytecode 2 | pytest 3 | -------------------------------------------------------------------------------- /vm/Lib/core_modules/codecs.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/codecs.py -------------------------------------------------------------------------------- /vm/Lib/core_modules/copyreg.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/copyreg.py -------------------------------------------------------------------------------- /Lib/test/test_importlib/data01/subdirectory/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data03/namespace/resource1.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespacedata01/binary.file: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/no-newlines.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /extra_tests/snippets/dir_module/relative.py: -------------------------------------------------------------------------------- 1 | value = 5 2 | -------------------------------------------------------------------------------- /rust-toolchain.toml: -------------------------------------------------------------------------------- 1 | [toolchain] 2 | channel = "stable" 3 | -------------------------------------------------------------------------------- /vm/Lib/python_builtins/__phello__: -------------------------------------------------------------------------------- 1 | ../../../Lib/__phello__ -------------------------------------------------------------------------------- /wasm/tests/.gitignore: -------------------------------------------------------------------------------- 1 | geckodriver.log 2 | Pipfile.lock 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/subpkg2/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data01/subdirectory/binary.file: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /Lib/test/test_importlib/data03/namespace/portion1/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data03/namespace/portion2/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/array/unclosed-empty.toml: -------------------------------------------------------------------------------- 1 | v=[ -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/trailing-comma.toml: -------------------------------------------------------------------------------- 1 | arr=[1,] -------------------------------------------------------------------------------- /extra_tests/snippets/dir_main/__main__.py: -------------------------------------------------------------------------------- 1 | print('Hello') 2 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.2.3.py: -------------------------------------------------------------------------------- 1 | print('C:\some\name') 2 | -------------------------------------------------------------------------------- /vm/Lib/python_builtins/__hello__.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/__hello__.py -------------------------------------------------------------------------------- /vm/Lib/python_builtins/_thread.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/_dummy_thread.py -------------------------------------------------------------------------------- /wasm/tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest 2 | selenium 3 | certifi 4 | -------------------------------------------------------------------------------- /Lib/concurrent/__init__.py: -------------------------------------------------------------------------------- 1 | # This directory is a Python package. 2 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_3131.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | € = 2 3 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data01/utf-8.file: -------------------------------------------------------------------------------- 1 | Hello, UTF-8 world! 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data02/one/resource1.txt: -------------------------------------------------------------------------------- 1 | one resource 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data02/two/resource2.txt: -------------------------------------------------------------------------------- 1 | two resource 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/array/file-end-after-val.toml: -------------------------------------------------------------------------------- 1 | a=[1 -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/non-scalar-escaped.toml: -------------------------------------------------------------------------------- 1 | a="\ud800" -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/table/eof-after-opening.toml: -------------------------------------------------------------------------------- 1 | [ -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/boolean.toml: -------------------------------------------------------------------------------- 1 | 'a'=true 2 | "b"=false -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N6_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | © -------------------------------------------------------------------------------- /Lib/xmlrpc/__init__.py: -------------------------------------------------------------------------------- 1 | # This directory is a Python package. 2 | -------------------------------------------------------------------------------- /benches/microbenchmarks/define_class.py: -------------------------------------------------------------------------------- 1 | class Foo: 2 | pass 3 | -------------------------------------------------------------------------------- /wasm/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | pkg/ 3 | dist/ 4 | node_modules/ 5 | 6 | -------------------------------------------------------------------------------- /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | # black's line length 3 | max-line-length = 88 4 | -------------------------------------------------------------------------------- /Lib/test/__init__.py: -------------------------------------------------------------------------------- 1 | # Dummy file to make this directory a package. 2 | -------------------------------------------------------------------------------- /Lib/test/__main__.py: -------------------------------------------------------------------------------- 1 | from test.libregrtest import main 2 | main() 3 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/array/unclosed-after-item.toml: -------------------------------------------------------------------------------- 1 | v=[1, -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/unclosed-empty.toml: -------------------------------------------------------------------------------- 1 | a={ -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/invalid-hex.toml: -------------------------------------------------------------------------------- 1 | hex = 0xgabba00f1 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/keys-and-vals/ends-early.toml: -------------------------------------------------------------------------------- 1 | fs.fw -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/empty-inline-table.json: -------------------------------------------------------------------------------- 1 | {"empty": {}} -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/no-newlines.toml: -------------------------------------------------------------------------------- 1 | #no newlines at all here -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.2.6.py: -------------------------------------------------------------------------------- 1 | assert 'Python' == 'Py' 'thon' 2 | -------------------------------------------------------------------------------- /extra_tests/snippets/xfail_assert.py: -------------------------------------------------------------------------------- 1 | assert 1 == 1 2 | assert 1 == 2 3 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/logo.png -------------------------------------------------------------------------------- /vm/Lib/core_modules/encodings_utf_8.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/encodings/utf_8.py -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/basic2.py: -------------------------------------------------------------------------------- 1 | from . import basic 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/not_a_namespace_pkg/foo/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespacedata01/utf-8.file: -------------------------------------------------------------------------------- 1 | Hello, UTF-8 world! 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/boolean/invalid-false-casing.toml: -------------------------------------------------------------------------------- 1 | val=falsE -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/boolean/invalid-true-casing.toml: -------------------------------------------------------------------------------- 1 | val=trUe -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/keys-and-vals/no-value.toml: -------------------------------------------------------------------------------- 1 | why-no-value= -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/keys-and-vals/only-ws-after-dot.toml: -------------------------------------------------------------------------------- 1 | fs. -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/literal-str/unclosed.toml: -------------------------------------------------------------------------------- 1 | unclosed='dwdd -------------------------------------------------------------------------------- /benches/microbenchmarks/define_function.py: -------------------------------------------------------------------------------- 1 | def function(): 2 | pass 3 | -------------------------------------------------------------------------------- /extra_tests/snippets/3.1.2.19.py: -------------------------------------------------------------------------------- 1 | s = "abcdefg" 2 | 3 | assert 7 == len(s) 4 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/util.py: -------------------------------------------------------------------------------- 1 | def util(): 2 | pass 3 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/module_and_namespace_package/a_test/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/array-missing-comma.toml: -------------------------------------------------------------------------------- 1 | arrr = [true false] 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/file-end-after-key-val.toml: -------------------------------------------------------------------------------- 1 | a={b=1 -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/unclosed-string.toml: -------------------------------------------------------------------------------- 1 | "a-string".must-be = "closed -------------------------------------------------------------------------------- /Lib/unittest/test/dummy.py: -------------------------------------------------------------------------------- 1 | # Empty module for testing the loading of modules 2 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.2.5.py: -------------------------------------------------------------------------------- 1 | assert 'unununium' == 3 * 'un' + 'ium' 2 | -------------------------------------------------------------------------------- /vm/Lib/python_builtins/_frozen_importlib.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/importlib/_bootstrap.py -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/indirect.py: -------------------------------------------------------------------------------- 1 | from . import basic, basic2 2 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/source.py: -------------------------------------------------------------------------------- 1 | from . import use 2 | spam = 1 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/subpkg/util.py: -------------------------------------------------------------------------------- 1 | def util(): 2 | pass 3 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/portion1/foo/one.py: -------------------------------------------------------------------------------- 1 | attr = 'portion1 foo one' 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/portion2/foo/two.py: -------------------------------------------------------------------------------- 1 | attr = 'portion2 foo two' 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/mutate.toml: -------------------------------------------------------------------------------- 1 | a = { b = 1 } 2 | a.b = 2 -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/keys-and-vals/ends-early-table-def.toml: -------------------------------------------------------------------------------- 1 | [fwfw.wafw -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-basic-str/file-ends-after-opening.toml: -------------------------------------------------------------------------------- 1 | a=""" -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/dates-and-times/localtime.toml: -------------------------------------------------------------------------------- 1 | t=00:00:00.99999999999999 -------------------------------------------------------------------------------- /benches/microbenchmarks/comprehension_list.py: -------------------------------------------------------------------------------- 1 | obj = [i for i in range(ITERATIONS)] 2 | -------------------------------------------------------------------------------- /benches/microbenchmarks/comprehension_set.py: -------------------------------------------------------------------------------- 1 | obj = {i for i in range(ITERATIONS)} 2 | -------------------------------------------------------------------------------- /extra_tests/snippets/3.1.3.5.py: -------------------------------------------------------------------------------- 1 | x = [1,999,3] 2 | x[1] = 2 3 | assert [1,2,3] == x 4 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/use.py: -------------------------------------------------------------------------------- 1 | from . import source 2 | source.spam 3 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/basic-str-ends-in-escape.toml: -------------------------------------------------------------------------------- 1 | "backslash is the last char\ -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/dotted-keys/access-non-table.toml: -------------------------------------------------------------------------------- 1 | a = false 2 | a.b = true -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-basic-str/escape-only.toml: -------------------------------------------------------------------------------- 1 | bee = """\""" 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-literal-str/file-ends-after-opening.toml: -------------------------------------------------------------------------------- 1 | a=''' -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/table/redefine-1.toml: -------------------------------------------------------------------------------- 1 | [t1] 2 | t2.t3.v = 0 3 | [t1.t2] 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/hex-char.toml: -------------------------------------------------------------------------------- 1 | a="\u0061" 2 | b="\u0062" 3 | c="\U00000063" -------------------------------------------------------------------------------- /benches/microbenchmarks/comprehension_dict.py: -------------------------------------------------------------------------------- 1 | obj = {i: i for i in range(ITERATIONS)} 2 | -------------------------------------------------------------------------------- /examples/freeze/freeze.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | print("Hello world!!!", time.time()) 4 | 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/3.1.3.4.py: -------------------------------------------------------------------------------- 1 | l = [1,2,3] 2 | assert [1,2,3,4,5] == (l + [4,5]) 3 | 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_len.py: -------------------------------------------------------------------------------- 1 | assert 3 == len([1,2,3]) 2 | assert 2 == len((1,2)) 3 | -------------------------------------------------------------------------------- /extra_tests/snippets/frozen.py: -------------------------------------------------------------------------------- 1 | import __hello__ 2 | assert __hello__.initialized == True 3 | -------------------------------------------------------------------------------- /extra_tests/snippets/scope_lambda.py: -------------------------------------------------------------------------------- 1 | class X: 2 | v = 10 3 | f = lambda x=v: x 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_warnings.py: -------------------------------------------------------------------------------- 1 | import _warnings 2 | 3 | _warnings.warn("Test") 4 | -------------------------------------------------------------------------------- /Lib/test/test_import/__main__.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | unittest.main('test.test_import') 4 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/from_cycle1.py: -------------------------------------------------------------------------------- 1 | from .from_cycle2 import a 2 | b = 1 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/from_cycle2.py: -------------------------------------------------------------------------------- 1 | from .from_cycle1 import b 2 | a = 1 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/package/__init__.py: -------------------------------------------------------------------------------- 1 | import package.submodule 2 | package.submodule 3 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/both_portions/foo/one.py: -------------------------------------------------------------------------------- 1 | attr = 'both_portions foo one' 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/both_portions/foo/two.py: -------------------------------------------------------------------------------- 1 | attr = 'both_portions foo two' 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/project1/parent/child/one.py: -------------------------------------------------------------------------------- 1 | attr = 'parent child one' 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/project2/parent/child/two.py: -------------------------------------------------------------------------------- 1 | attr = 'parent child two' 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/array-of-tables/overwrite-bool-with-aot.toml: -------------------------------------------------------------------------------- 1 | a=true 2 | [[a]] -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/define-twice.toml: -------------------------------------------------------------------------------- 1 | table = { dupe = 1, dupe = 2 } -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/invalid-escaped-unicode.toml: -------------------------------------------------------------------------------- 1 | escaped-unicode = "\uabag" 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-literal-str/unclosed.toml: -------------------------------------------------------------------------------- 1 | bee = ''' 2 | hee 3 | gee '' -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/table/redefine-2.toml: -------------------------------------------------------------------------------- 1 | [t1] 2 | t2.t3.v = 0 3 | [t1.t2.t3] 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/empty-inline-table.toml: -------------------------------------------------------------------------------- 1 | empty ={ }#nothing here 2 | -------------------------------------------------------------------------------- /Lib/test/testtar.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/testtar.tar -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N5_c14nTrim.xml: -------------------------------------------------------------------------------- 1 | Hello, world! -------------------------------------------------------------------------------- /Lib/test/zipdir.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/zipdir.zip -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | pub fn main() -> std::process::ExitCode { 2 | rustpython::run(|_vm| {}) 3 | } 4 | -------------------------------------------------------------------------------- /vm/.gitignore: -------------------------------------------------------------------------------- 1 | venv/ 2 | tests/*.bytecode 3 | Cargo.lock 4 | python_compiler/target 5 | target/ 6 | -------------------------------------------------------------------------------- /vm/Lib/python_builtins/_frozen_importlib_external.py: -------------------------------------------------------------------------------- 1 | ../../../Lib/importlib/_bootstrap_external.py -------------------------------------------------------------------------------- /Lib/test/cfgparser.1: -------------------------------------------------------------------------------- 1 | # Also used by idlelib.test_idle.test_config. 2 | [Foo Bar] 3 | foo=newbar 4 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/module_and_namespace_package/a_test.py: -------------------------------------------------------------------------------- 1 | attr = 'in module' 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/not_a_namespace_pkg/foo/one.py: -------------------------------------------------------------------------------- 1 | attr = 'portion1 foo one' 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/project3/parent/child/three.py: -------------------------------------------------------------------------------- 1 | attr = 'parent child three' 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/overwrite-implicitly.toml: -------------------------------------------------------------------------------- 1 | a = { b = 1, b.c = 2 } 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/invalid-comment-char.toml: -------------------------------------------------------------------------------- 1 | # form feed ( ) not allowed in comments -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/keys-and-vals/overwrite-with-deep-table.toml: -------------------------------------------------------------------------------- 1 | a=1 2 | [a.b.c.d] 3 | -------------------------------------------------------------------------------- /benches/microbenchmarks/addition.py: -------------------------------------------------------------------------------- 1 | total = 0 2 | for i in range(ITERATIONS): 3 | total += i 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/import_mutual2.py: -------------------------------------------------------------------------------- 1 | 2 | # Mutual recursive import: 3 | import import_mutual1 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/import_name.py: -------------------------------------------------------------------------------- 1 | def import_func(): 2 | assert __name__ == "import_name" 3 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.1.6.py: -------------------------------------------------------------------------------- 1 | assert 7.5 == 3 * 3.75 / 1.5 2 | 3 | assert 3.5 == 7.0 / 2 4 | -------------------------------------------------------------------------------- /benches/microbenchmarks/construct_object.py: -------------------------------------------------------------------------------- 1 | class Foo: 2 | pass 3 | 4 | 5 | # --- 6 | 7 | Foo() 8 | -------------------------------------------------------------------------------- /extra_tests/snippets/import_mutual1.py: -------------------------------------------------------------------------------- 1 | 2 | # Mutual recursive import: 3 | import import_mutual2 4 | 5 | -------------------------------------------------------------------------------- /Lib/ctypes/test/__main__.py: -------------------------------------------------------------------------------- 1 | from ctypes.test import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/__main__.py: -------------------------------------------------------------------------------- 1 | from . import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/dotted-keys/extend-defined-aot.toml: -------------------------------------------------------------------------------- 1 | [[tab.arr]] 2 | [tab] 3 | arr.val1=1 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/missing-closing-square-bracket.toml: -------------------------------------------------------------------------------- 1 | [closing-bracket.missingö 2 | blaa=2 3 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inC14N6.xml: -------------------------------------------------------------------------------- 1 | 2 | © 3 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N5_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | Hello, world! 3 | -------------------------------------------------------------------------------- /benches/microbenchmarks/call_simple.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | a + b 3 | 4 | 5 | # --- 6 | 7 | add(1, 2) 8 | -------------------------------------------------------------------------------- /benches/microbenchmarks/list_count_builtins.py: -------------------------------------------------------------------------------- 1 | l = [i for i in range(ITERATIONS)] 2 | 3 | # --- 4 | l.count(1) -------------------------------------------------------------------------------- /benches/microbenchmarks/strings.py: -------------------------------------------------------------------------------- 1 | long_string = "a" * 50000 2 | 3 | for char in long_string: 4 | pass 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/3.1.2.16.py: -------------------------------------------------------------------------------- 1 | word = "Python" 2 | assert "on" == word[4:42] 3 | assert "" == word[42:] 4 | -------------------------------------------------------------------------------- /wasm/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "tabWidth": 4, 4 | "arrowParens": "always" 5 | } 6 | -------------------------------------------------------------------------------- /wasm/notebook/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/wasm/notebook/screenshot.png -------------------------------------------------------------------------------- /Lib/ctypes/macholib/fetch_macholib.bat: -------------------------------------------------------------------------------- 1 | svn export --force http://svn.red-bean.com/bob/macholib/trunk/macholib/ . 2 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_pep3120.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/badsyntax_pep3120.py -------------------------------------------------------------------------------- /Lib/test/test_importlib/builtin/__main__.py: -------------------------------------------------------------------------------- 1 | from . import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/frozen/__main__.py: -------------------------------------------------------------------------------- 1 | from . import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/import_/__main__.py: -------------------------------------------------------------------------------- 1 | from . import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/source/__main__.py: -------------------------------------------------------------------------------- 1 | from . import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_json/__main__.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from test.test_json import load_tests 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/dates-and-times/invalid-day.toml: -------------------------------------------------------------------------------- 1 | "only 28 or 29 days in february" = 1988-02-30 2 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/test.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/xmltestdata/test.xml -------------------------------------------------------------------------------- /Lib/test/zip_cp437_header.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/zip_cp437_header.zip -------------------------------------------------------------------------------- /benches/microbenchmarks/call_kwargs.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | a + b 3 | 4 | 5 | # --- 6 | 7 | add(a=1, b=10) 8 | -------------------------------------------------------------------------------- /extra_tests/snippets/dir_module/__init__.py: -------------------------------------------------------------------------------- 1 | from .relative import value 2 | from .dir_module_inner import value2 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/binding2.py: -------------------------------------------------------------------------------- 1 | import test.test_import.data.circular_imports.binding as binding 2 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/subpkg/subpackage2.py: -------------------------------------------------------------------------------- 1 | #from .util import util 2 | from .. import subpackage 3 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/extension/__main__.py: -------------------------------------------------------------------------------- 1 | from . import load_tests 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/dotted-keys/extend-defined-table.toml: -------------------------------------------------------------------------------- 1 | [a.b.c] 2 | z = 9 3 | [a] 4 | b.c.t = 9 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table-missing-comma.toml: -------------------------------------------------------------------------------- 1 | arrr = { comma-missing = true valid-toml = false } 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/define-twice-in-subtable.toml: -------------------------------------------------------------------------------- 1 | table1 = { table2.dupe = 1, table2.dupe = 2 } -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/missing-closing-double-square-bracket.toml: -------------------------------------------------------------------------------- 1 | [[closing-bracket.missing] 2 | blaa=2 3 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-basic-str/last-line-escape.toml: -------------------------------------------------------------------------------- 1 | bee = """ 2 | hee \ 3 | 4 | gee \ """ 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-basic-str/unclosed-ends-in-whitespace-escape.toml: -------------------------------------------------------------------------------- 1 | bee = """ 2 | hee 3 | gee\ -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/unclosed-multiline-string.toml: -------------------------------------------------------------------------------- 1 | not-closed= """ 2 | diibaa 3 | blibae ete 4 | eteta 5 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/test.xml.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/xmltestdata/test.xml.out -------------------------------------------------------------------------------- /Lib/test/ziptestdata/exe_with_z64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/ziptestdata/exe_with_z64 -------------------------------------------------------------------------------- /Lib/test/ziptestdata/exe_with_zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/ziptestdata/exe_with_zip -------------------------------------------------------------------------------- /Lib/xml/etree/cElementTree.py: -------------------------------------------------------------------------------- 1 | # Deprecated alias for xml.etree.ElementTree 2 | 3 | from xml.etree.ElementTree import * 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_thread.py: -------------------------------------------------------------------------------- 1 | import _thread 2 | 3 | assert _thread.TIMEOUT_MAX in [9223372036.0, 4294967.0] 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/dir_module/dir_module_inner/__init__.py: -------------------------------------------------------------------------------- 1 | from ..relative import value 2 | 3 | value2 = value + 2 4 | -------------------------------------------------------------------------------- /Lib/ctypes/macholib/fetch_macholib: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | svn export --force http://svn.red-bean.com/bob/macholib/trunk/macholib/ . 3 | -------------------------------------------------------------------------------- /Lib/test/ann_module4.py: -------------------------------------------------------------------------------- 1 | # This ann_module isn't for test_typing, 2 | # it's for test_module 3 | 4 | a:int=3 5 | b:str=4 6 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/binding.py: -------------------------------------------------------------------------------- 1 | import test.test_import.data.circular_imports.binding2 as binding2 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/dates-and-times/localtime.json: -------------------------------------------------------------------------------- 1 | {"t": 2 | {"type":"time-local","value":"00:00:00.999999"}} 3 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/doc.dtd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Lib/test/ziptestdata/testdata_module_inside_zip.py: -------------------------------------------------------------------------------- 1 | # Test data file to be stored within a zip file. 2 | FAVORITE_NUMBER = 5 3 | -------------------------------------------------------------------------------- /benches/microbenchmarks/exception_simple.py: -------------------------------------------------------------------------------- 1 | try: 2 | raise RuntimeError() 3 | except RuntimeError as e: 4 | pass 5 | -------------------------------------------------------------------------------- /benches/microbenchmarks/loop_append.py: -------------------------------------------------------------------------------- 1 | obj = [] 2 | 3 | # --- 4 | 5 | for i in range(ITERATIONS): 6 | obj.append(i) 7 | -------------------------------------------------------------------------------- /benches/microbenchmarks/loop_string.py: -------------------------------------------------------------------------------- 1 | string = "a" * ITERATIONS 2 | 3 | # --- 4 | 5 | for char in string: 6 | pass 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.1.3.py: -------------------------------------------------------------------------------- 1 | assert 25 == 5 ** 2 # 5 squared 2 | 3 | assert 128 == 2 ** 7 # 2 to the power of 7 4 | -------------------------------------------------------------------------------- /Lib/ensurepip/__main__.py: -------------------------------------------------------------------------------- 1 | import ensurepip 2 | import sys 3 | 4 | if __name__ == "__main__": 5 | sys.exit(ensurepip._main()) 6 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/package2/submodule1.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.modules.pop(__package__, None) 3 | from . import submodule2 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/__main__.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | from test.test_tomllib import load_tests 4 | 5 | 6 | unittest.main() 7 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/override-val-with-array.toml: -------------------------------------------------------------------------------- 1 | inline-t = { nest = {} } 2 | 3 | [[inline-t.nest]] 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/override-val-with-table.toml: -------------------------------------------------------------------------------- 1 | inline-t = { nest = {} } 2 | 3 | [inline-t.nest] 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/dates-and-times/datetimes.toml: -------------------------------------------------------------------------------- 1 | local-dt=1988-10-27t01:01:01 2 | zulu-dt=1988-10-27t01:01:01z 3 | -------------------------------------------------------------------------------- /compiler/parser/src/python.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::all)] 2 | #![allow(unused)] 3 | include!(concat!(env!("OUT_DIR"), "/python.rs")); 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/3.1.2.18.py: -------------------------------------------------------------------------------- 1 | word = "Python" 2 | 3 | assert "Jython" == "J" + word[1:] 4 | assert "Pypy" == word[:2] + "py" 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.1.4.py: -------------------------------------------------------------------------------- 1 | width = 20 2 | height = 5 * 9 3 | assert 900 == width * height 4 | print(width * height) 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_decimal.py: -------------------------------------------------------------------------------- 1 | try: 2 | eval("0.E") 3 | except SyntaxError: 4 | pass 5 | else: 6 | assert False 7 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future10.py: -------------------------------------------------------------------------------- 1 | from __future__ import absolute_import 2 | "spam, bar, blah" 3 | from __future__ import print_function 4 | -------------------------------------------------------------------------------- /Lib/test/encoded_modules/module_koi8_r.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/encoded_modules/module_koi8_r.py -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/basic.py: -------------------------------------------------------------------------------- 1 | """Circular imports through direct, relative imports.""" 2 | from . import basic2 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/rebinding2.py: -------------------------------------------------------------------------------- 1 | from .subpkg import util 2 | from . import rebinding 3 | util = util.util 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/overwrite-value-in-inner-array.toml: -------------------------------------------------------------------------------- 1 | tab = { inner.table = [{}], inner.table.val = "bad" } -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/overwrite-value-in-inner-table.toml: -------------------------------------------------------------------------------- 1 | tab = { inner = { dog = "best" }, inner.cat = "worst" } -------------------------------------------------------------------------------- /examples/atexit_example.py: -------------------------------------------------------------------------------- 1 | import atexit 2 | import sys 3 | 4 | def myexit(): 5 | sys.exit(2) 6 | 7 | atexit.register(myexit) 8 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_eval.py: -------------------------------------------------------------------------------- 1 | assert 3 == eval('1+2') 2 | 3 | code = compile('5+3', 'x.py', 'eval') 4 | assert eval(code) == 8 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/import_file.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def import_file(): 4 | assert os.path.basename(__file__) == "import_file.py" 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/import_star.py: -------------------------------------------------------------------------------- 1 | # This is used by import.py; the two should be modified in concert 2 | 3 | STAR_IMPORT = '123' 4 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/subpackage.py: -------------------------------------------------------------------------------- 1 | """Circular import involving a sub-package.""" 2 | from .subpkg import subpackage2 3 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/subpkg2/parent/__init__.py: -------------------------------------------------------------------------------- 1 | import test.test_import.data.circular_imports.subpkg2.parent.child 2 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data01/utf-16.file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/data01/utf-16.file -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/dotted-keys/extend-defined-table-with-subtable.toml: -------------------------------------------------------------------------------- 1 | [a.b.c.d] 2 | z = 9 3 | [a] 4 | b.c.d.k.t = 8 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/array/array-subtables.toml: -------------------------------------------------------------------------------- 1 | [[arr]] 2 | [arr.subtab] 3 | val=1 4 | 5 | [[arr]] 6 | [arr.subtab] 7 | val=2 8 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/boolean.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": {"type":"bool","value":"true"}, 3 | "b": {"type":"bool","value":"false"} 4 | } 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/multiline-basic-str/ends-in-whitespace-escape.json: -------------------------------------------------------------------------------- 1 | {"beee": {"type": "string", "value": "heeee\ngeeee"}} 2 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsDefault_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /extra_tests/.gitignore: -------------------------------------------------------------------------------- 1 | snippets/whats_left_*.py 2 | .cache/ 3 | cpython_tests_results.json 4 | cpython_generated_slices.py 5 | Pipfile.lock 6 | -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.bmp -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.exr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.exr -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.gif -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.jpg -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.pbm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.pbm -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.pgm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.pgm -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.png -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.ppm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.ppm -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.ras: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.ras -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.sgi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.sgi -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.tiff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.tiff -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/extra_tests/snippets/imghdrdata/python.webp -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.Dockerfile 3 | 4 | vscode: 5 | extensions: 6 | - vadimcn.vscode-lldb@1.5.3:vTh/rWhvJ5nQpeAVsD20QA== -------------------------------------------------------------------------------- /Lib/__phello__/spam.py: -------------------------------------------------------------------------------- 1 | initialized = True 2 | 3 | def main(): 4 | print("Hello world!") 5 | 6 | if __name__ == '__main__': 7 | main() 8 | -------------------------------------------------------------------------------- /Lib/pydoc_data/_pydoc.css: -------------------------------------------------------------------------------- 1 | /* 2 | CSS file for pydoc. 3 | 4 | Contents of this file are subject to change without notice. 5 | 6 | */ 7 | -------------------------------------------------------------------------------- /Lib/test/encoded_modules/module_iso_8859_1.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/encoded_modules/module_iso_8859_1.py -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/multiline-basic-str/carriage-return.toml: -------------------------------------------------------------------------------- 1 | s="""cr is not an allowed line ending but we just tried to use it 2 | """ -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/apostrophes-in-literal-string.toml: -------------------------------------------------------------------------------- 1 | this-str-has-apostrophes='''' there's one already 2 | '' two more 3 | ''''' 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/array/open-parent-table.toml: -------------------------------------------------------------------------------- 1 | [[parent-table.arr]] 2 | [[parent-table.arr]] 3 | [parent-table] 4 | not-arr = 1 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/multiline-basic-str/ends-in-whitespace-escape.toml: -------------------------------------------------------------------------------- 1 | beee = """ 2 | heeee 3 | geeee\ 4 | 5 | 6 | """ 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_abs.py: -------------------------------------------------------------------------------- 1 | assert abs(-3) == 3 2 | assert abs(7) == 7 3 | assert abs(-3.21) == 3.21 4 | assert abs(6.25) == 6.25 5 | 6 | -------------------------------------------------------------------------------- /Lib/__phello__/__init__.py: -------------------------------------------------------------------------------- 1 | initialized = True 2 | 3 | def main(): 4 | print("Hello world!") 5 | 6 | if __name__ == '__main__': 7 | main() 8 | -------------------------------------------------------------------------------- /Lib/collections/abc.py: -------------------------------------------------------------------------------- 1 | from _collections_abc import * 2 | from _collections_abc import __all__ 3 | from _collections_abc import _CallableGenericAlias 4 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/array-of-tables/overwrite-array-in-parent.toml: -------------------------------------------------------------------------------- 1 | [[parent-table.arr]] 2 | [parent-table] 3 | not-arr = 1 4 | arr = 2 5 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N2_c14nTrim.xml: -------------------------------------------------------------------------------- 1 | A BABA BC -------------------------------------------------------------------------------- /jit/tests/lib.rs: -------------------------------------------------------------------------------- 1 | #[macro_use] 2 | mod common; 3 | mod bool_tests; 4 | mod float_tests; 5 | mod int_tests; 6 | mod misc_tests; 7 | mod none_tests; 8 | -------------------------------------------------------------------------------- /Lib/ensurepip/_bundled/pip-22.3.1-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/ensurepip/_bundled/pip-22.3.1-py3-none-any.whl -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespacedata01/utf-16.file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/namespacedata01/utf-16.file -------------------------------------------------------------------------------- /Lib/test/test_importlib/zipdata01/ziptestdata.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/zipdata01/ziptestdata.zip -------------------------------------------------------------------------------- /Lib/test/test_importlib/zipdata02/ziptestdata.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/zipdata02/ziptestdata.zip -------------------------------------------------------------------------------- /.theia/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cpp.buildConfigurations": [ 3 | { 4 | "name": "", 5 | "directory": "" 6 | }, 7 | ] 8 | } -------------------------------------------------------------------------------- /Lib/contextvars.py: -------------------------------------------------------------------------------- 1 | from _contextvars import Context, ContextVar, Token, copy_context 2 | 3 | 4 | __all__ = ('Context', 'ContextVar', 'Token', 'copy_context') 5 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data/example-21.12-py3.6.egg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/data/example-21.12-py3.6.egg -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsDefault_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Lib/test/test_sqlite3/__main__.py: -------------------------------------------------------------------------------- 1 | from test.test_sqlite3 import load_tests # Needed for the "load tests" protocol. 2 | import unittest 3 | 4 | unittest.main() 5 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/invalid/inline-table/override-val-in-table.toml: -------------------------------------------------------------------------------- 1 | [tab.nested] 2 | inline-t = { nest = {} } 3 | 4 | [tab] 5 | nested.inline-t.nest = 2 6 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N1_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 3 | Hello, world! 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_reversed.py: -------------------------------------------------------------------------------- 1 | assert list(reversed(range(5))) == [4, 3, 2, 1, 0] 2 | 3 | l = [5,4,3,2,1] 4 | assert list(reversed(l)) == [1,2,3,4,5] 5 | -------------------------------------------------------------------------------- /vm/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | mod slot; 2 | mod structseq; 3 | mod zoo; 4 | 5 | pub use slot::*; 6 | pub use structseq::PyStructSequence; 7 | pub(crate) use zoo::TypeZoo; 8 | -------------------------------------------------------------------------------- /Lib/asyncio/log.py: -------------------------------------------------------------------------------- 1 | """Logging configuration.""" 2 | 3 | import logging 4 | 5 | 6 | # Name the logger after the package. 7 | logger = logging.getLogger(__package__) 8 | -------------------------------------------------------------------------------- /Lib/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/ensurepip/_bundled/setuptools-65.5.0-py3-none-any.whl -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/nested_portion1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/namespace_pkgs/nested_portion1.zip -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/apostrophes-in-literal-string.json: -------------------------------------------------------------------------------- 1 | {"this-str-has-apostrophes": {"type": "string", "value": "' there's one already\n'' two more\n''"}} 2 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/five-quotes.toml: -------------------------------------------------------------------------------- 1 | five-quotes = """ 2 | Closing with five quotes 3 | """"" 4 | four-quotes = """ 5 | Closing with four quotes 6 | """" 7 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/trailing-comma.json: -------------------------------------------------------------------------------- 1 | {"arr": 2 | {"type":"array","value": 3 | [ 4 | {"type":"integer","value":"1"} 5 | ] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_empty.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/parser.rs 3 | expression: parse_ast 4 | --- 5 | [] 6 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/data/example-21.12-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/data/example-21.12-py3-none-any.whl -------------------------------------------------------------------------------- /Lib/test/test_importlib/data/example2-1.0.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/data/example2-1.0.0-py3-none-any.whl -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/missing_directory.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/namespace_pkgs/missing_directory.zip -------------------------------------------------------------------------------- /Lib/test/test_importlib/namespace_pkgs/top_level_portion1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/astral-sh/RustPython/HEAD/Lib/test/test_importlib/namespace_pkgs/top_level_portion1.zip -------------------------------------------------------------------------------- /Lib/test/xmltestdata/simple.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | text 4 | texttail 5 | 6 | 7 | -------------------------------------------------------------------------------- /benches/microbenchmarks/list_count_custom_eq.py: -------------------------------------------------------------------------------- 1 | class A: 2 | def __eq__(self, other): 3 | return True 4 | 5 | l = [A()] * ITERATIONS 6 | 7 | # --- 8 | l.count(1) -------------------------------------------------------------------------------- /extra_tests/benchmarks/perf_add.py: -------------------------------------------------------------------------------- 1 | j = 0 2 | while j < 1000: 3 | total = 0 4 | i = 0 5 | while i < 100: 6 | total += i 7 | i += 1 8 | j += 1 9 | -------------------------------------------------------------------------------- /Lib/distutils/debug.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | # If DISTUTILS_DEBUG is anything other than the empty string, we run in 4 | # debug mode. 5 | DEBUG = os.environ.get('DISTUTILS_DEBUG') 6 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/hex-char.json: -------------------------------------------------------------------------------- 1 | { 2 | "a": {"type":"string","value":"a"}, 3 | "b": {"type":"string","value":"b"}, 4 | "c": {"type":"string","value":"c"} 5 | } 6 | -------------------------------------------------------------------------------- /benches/microbenchmarks/cmp.py: -------------------------------------------------------------------------------- 1 | a = 10 2 | b = 20 3 | 4 | for _ in range(10000): 5 | a > b 6 | a >= b 7 | a < b 8 | a <= b 9 | a == b 10 | a != b 11 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_file.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from import_file import import_file 4 | 5 | import_file() 6 | 7 | assert os.path.basename(__file__) == "builtin_file.py" 8 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "image": "mcr.microsoft.com/devcontainers/universal:2", 3 | "features": { 4 | "ghcr.io/devcontainers/features/rust:1": {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_statement.py: -------------------------------------------------------------------------------- 1 | 2 | # Test several statement types 3 | 4 | # small ones, seperated by ';': 5 | 6 | if True: 7 | 5;4; 8 | b=4 9 | b; 10 | -------------------------------------------------------------------------------- /wasm/example/src/main.js: -------------------------------------------------------------------------------- 1 | import * as rp from 'rustpython_wasm'; 2 | import pyCode from 'raw-loader!./main.py'; 3 | 4 | const vm = rp.vmStore.get('main'); 5 | 6 | vm.exec(pyCode); 7 | -------------------------------------------------------------------------------- /Lib/test/ann_module6.py: -------------------------------------------------------------------------------- 1 | # Tests that top-level ClassVar is not allowed 2 | 3 | from __future__ import annotations 4 | 5 | from typing import ClassVar 6 | 7 | wrong: ClassVar[int] = 1 8 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/rebinding.py: -------------------------------------------------------------------------------- 1 | """Test the binding of names when a circular import shares the same name as an 2 | attribute.""" 3 | from .rebinding2 import util 4 | -------------------------------------------------------------------------------- /Lib/test/subprocessdata/input_reader.py: -------------------------------------------------------------------------------- 1 | """When called as a script, consumes the input""" 2 | 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | for line in sys.stdin: 7 | pass 8 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/circular_imports/subpkg2/parent/child.py: -------------------------------------------------------------------------------- 1 | import test.test_import.data.circular_imports.subpkg2.parent 2 | 3 | test.test_import.data.circular_imports.subpkg2.parent 4 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from test.support import load_package_tests 3 | 4 | def load_tests(*args): 5 | return load_package_tests(os.path.dirname(__file__), *args) 6 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsPushdown.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsSuperfluous_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /demo_closures.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def foo(x): 4 | def bar(z): 5 | return z + x 6 | return bar 7 | 8 | f = foo(9) 9 | g = foo(10) 10 | 11 | print(f(2)) 12 | print(g(2)) 13 | 14 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future8.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | 3 | from __future__ import * 4 | 5 | def f(x): 6 | def g(y): 7 | return x + y 8 | return g 9 | 10 | print(f(2)(4)) 11 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsXml_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | data 3 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_empty_fstring.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: "parse_fstring(\"\").unwrap()" 4 | --- 5 | [] 6 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/builtin/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from test.support import load_package_tests 3 | 4 | def load_tests(*args): 5 | return load_package_tests(os.path.dirname(__file__), *args) 6 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/extension/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from test.support import load_package_tests 3 | 4 | def load_tests(*args): 5 | return load_package_tests(os.path.dirname(__file__), *args) 6 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/frozen/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from test.support import load_package_tests 3 | 4 | def load_tests(*args): 5 | return load_package_tests(os.path.dirname(__file__), *args) 6 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/import_/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from test.support import load_package_tests 3 | 4 | def load_tests(*args): 5 | return load_package_tests(os.path.dirname(__file__), *args) 6 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/source/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | from test.support import load_package_tests 3 | 4 | def load_tests(*args): 5 | return load_package_tests(os.path.dirname(__file__), *args) 6 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/array/open-parent-table.json: -------------------------------------------------------------------------------- 1 | { 2 | "parent-table": { 3 | "arr": {"type":"array","value":[{},{}]}, 4 | "not-arr": {"type":"integer","value":"1"} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/non_utf8.txt: -------------------------------------------------------------------------------- 1 | " ġÄ%\N{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\222{{˘"ġ›"Ûˇˇ$"ˇÄ%\N{222+-. ġÄ%\N{222{{˘"ġ› 2 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/doc.xsl: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsXml_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | data 3 | -------------------------------------------------------------------------------- /benches/microbenchmarks/exception_nested.py: -------------------------------------------------------------------------------- 1 | try: 2 | try: 3 | raise ValueError() 4 | except ValueError as e: 5 | raise RuntimeError() from e 6 | except RuntimeError as e: 7 | pass 8 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.2.4.py: -------------------------------------------------------------------------------- 1 | print("""\ 2 | Usage: thingy [OPTIONS] 3 | -h Display this usage message 4 | -H hostname Hostname to connect to 5 | """) 6 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_call_nested.py: -------------------------------------------------------------------------------- 1 | # Blocked on LOAD_GLOBAL 2 | def sum(x,y): 3 | return x+y 4 | 5 | def total(a,b,c,d): 6 | return sum(sum(a,b),sum(c,d)) 7 | 8 | assert total(1,2,3,4) == 10 9 | -------------------------------------------------------------------------------- /Lib/test/dataclass_textanno.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import dataclasses 4 | 5 | 6 | class Foo: 7 | pass 8 | 9 | 10 | @dataclasses.dataclass 11 | class Bar: 12 | foo: Foo 13 | -------------------------------------------------------------------------------- /Lib/test/subprocessdata/qcat.py: -------------------------------------------------------------------------------- 1 | """When ran as a script, simulates cat with no arguments.""" 2 | 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | for line in sys.stdin: 7 | sys.stdout.write(line) 8 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/dates-and-times/datetimes.json: -------------------------------------------------------------------------------- 1 | { 2 | "local-dt": {"type":"datetime-local","value":"1988-10-27t01:01:01"}, 3 | "zulu-dt": {"type":"datetime","value":"1988-10-27t01:01:01z"} 4 | } 5 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/simple-ns.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | text 5 | texttail 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lib/venv/__main__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from . import main 3 | 4 | rc = 1 5 | try: 6 | main() 7 | rc = 0 8 | except Exception as e: 9 | print('Error: %s' % e, file=sys.stderr) 10 | sys.exit(rc) 11 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_hex.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | assert hex(16) == '0x10' 4 | assert hex(-16) == '-0x10' 5 | 6 | assert_raises(TypeError, hex, {}, _msg='ord() called with dict') 7 | -------------------------------------------------------------------------------- /ruff_text_size/tests/indexing.rs: -------------------------------------------------------------------------------- 1 | use ruff_text_size::TextRange; 2 | 3 | #[test] 4 | fn main() { 5 | let range = TextRange::default(); 6 | let _ = &""[range]; 7 | let _ = &String::new()[range]; 8 | } 9 | -------------------------------------------------------------------------------- /wasm/demo/snippets/fizzbuzz.py: -------------------------------------------------------------------------------- 1 | for i in range(1, 100): 2 | print(f"{i} ", end="") 3 | if not i % 3: 4 | print("fizz", end="") 5 | if not i % 5: 6 | print("buzz", end="") 7 | print() 8 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future9.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | 3 | from __future__ import nested_scopes, braces 4 | 5 | def f(x): 6 | def g(y): 7 | return x + y 8 | return g 9 | 10 | print(f(2)(4)) 11 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/five-quotes.json: -------------------------------------------------------------------------------- 1 | { 2 | "five-quotes": {"type":"string","value":"Closing with five quotes\n\"\""}, 3 | "four-quotes": {"type":"string","value":"Closing with four quotes\n\""} 4 | } 5 | -------------------------------------------------------------------------------- /Lib/test/tracedmodules/testmod.py: -------------------------------------------------------------------------------- 1 | def func(x): 2 | b = x + 1 3 | return b + 2 4 | 5 | def func2(): 6 | """Test function for issue 9936 """ 7 | return (1, 8 | 2, 9 | 3) 10 | -------------------------------------------------------------------------------- /Lib/test/future_test2.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | 3 | from __future__ import nested_scopes; import site 4 | 5 | def f(x): 6 | def g(y): 7 | return x + y 8 | return g 9 | 10 | result = f(2)(4) 11 | -------------------------------------------------------------------------------- /Lib/xml/parsers/__init__.py: -------------------------------------------------------------------------------- 1 | """Python interfaces to XML parsers. 2 | 3 | This package contains one module: 4 | 5 | expat -- Python wrapper for James Clark's Expat parser, with namespace 6 | support. 7 | 8 | """ 9 | -------------------------------------------------------------------------------- /.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [target.'cfg(target_env = "msvc")'] 2 | rustflags = "-C link-arg=/STACK:8000000" 3 | 4 | [target.'cfg(all(target_os = "windows", not(target_env = "msvc")))'] 5 | rustflags = "-C link-args=-Wl,--stack,8000000" 6 | -------------------------------------------------------------------------------- /Lib/ctypes/macholib/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Enough Mach-O to make your head spin. 3 | 4 | See the relevant header files in /usr/include/mach-o 5 | 6 | And also Apple's documentation. 7 | """ 8 | 9 | __version__ = '1.0' 10 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future4.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | import __future__ 3 | from __future__ import nested_scopes 4 | 5 | def f(x): 6 | def g(y): 7 | return x + y 8 | return g 9 | 10 | result = f(2)(4) 11 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsRedecl.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsSort.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N1_c14nComment.xml: -------------------------------------------------------------------------------- 1 | 3 | Hello, world! 4 | 5 | 6 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_if.py: -------------------------------------------------------------------------------- 1 | x = 0 2 | if 1 == 1: 3 | x += 5 4 | else: 5 | x += 3 6 | 7 | assert x == 5 8 | 9 | y = 0 10 | if 1 == 2: 11 | y += 5 12 | else: 13 | y += 3 14 | 15 | assert y == 3 16 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsXml.xml: -------------------------------------------------------------------------------- 1 | 2 | data 3 | 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/import_target.py: -------------------------------------------------------------------------------- 1 | # This is used by import.py; the two should be modified in concert 2 | 3 | X = '123' 4 | Y = 'abc' 5 | 6 | def func(): 7 | return X 8 | 9 | def other_func(): 10 | return Y 11 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_operator.py: -------------------------------------------------------------------------------- 1 | import _operator 2 | 3 | assert _operator._compare_digest("abcdef", "abcdef") 4 | assert not _operator._compare_digest("abcdef", "abc") 5 | assert not _operator._compare_digest("abc", "abcdef") 6 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future6.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | "this isn't a doc string" 3 | from __future__ import nested_scopes 4 | 5 | def f(x): 6 | def g(y): 7 | return x + y 8 | return g 9 | 10 | result = f(2)(4) 11 | -------------------------------------------------------------------------------- /Lib/test/libregrtest/__init__.py: -------------------------------------------------------------------------------- 1 | # We import importlib *ASAP* in order to test #15386 2 | import importlib 3 | 4 | from test.libregrtest.cmdline import _parse_args, RESOURCE_NAMES, ALL_RESOURCES 5 | from test.libregrtest.main import main 6 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsRedecl_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsXml_c14nQname.xml: -------------------------------------------------------------------------------- 1 | 2 | data 3 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_comma.py: -------------------------------------------------------------------------------- 1 | list1 = ["a", "b",] 2 | list2 = [ 3 | "a", 4 | "b", 5 | ] 6 | assert list1 == list2 7 | 8 | dict1 = {"a": "b",} 9 | dict2 = { 10 | "a": "b", 11 | } 12 | #assert dict1 == dict2 13 | -------------------------------------------------------------------------------- /Lib/asyncio/constants.py: -------------------------------------------------------------------------------- 1 | """Constants.""" 2 | 3 | # After the connection is lost, log warnings after this many write()s. 4 | LOG_THRESHOLD_FOR_CONNLOST_WRITES = 5 5 | 6 | # Seconds to wait before retrying accept(). 7 | ACCEPT_RETRY_DELAY = 1 8 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsRedecl_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_while.py: -------------------------------------------------------------------------------- 1 | # i = 0 2 | # while i < 5: 3 | # i += 1 4 | # # print(i) 5 | # assert i == 5 6 | 7 | i = 0 8 | while i < 5: 9 | i += 1 10 | # print(i) 11 | if i == 3: 12 | break 13 | assert i == 3 14 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future3.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | from __future__ import nested_scopes 3 | from __future__ import rested_snopes 4 | 5 | def f(x): 6 | def g(y): 7 | return x + y 8 | return g 9 | 10 | result = f(2)(4) 11 | -------------------------------------------------------------------------------- /Lib/test/tracedmodules/__init__.py: -------------------------------------------------------------------------------- 1 | """This package contains modules that help testing the trace.py module. Note 2 | that the exact location of functions in these modules is important, as trace.py 3 | takes the real line numbers into account. 4 | """ 5 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsSuperfluous.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsSort_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.1.1.py: -------------------------------------------------------------------------------- 1 | assert 2 + 2 == 4 2 | 3 | assert 50 - 5*6 == 20 4 | 5 | assert (50 - 5*6) / 4 == 5 # This will crash 6 | assert (50 - 5*6) / 4 == 5.0 7 | 8 | assert 8 / 5 == 1.6 # division always returns a floating point number 9 | -------------------------------------------------------------------------------- /vm/src/prelude.rs: -------------------------------------------------------------------------------- 1 | pub use crate::{ 2 | object::{ 3 | AsObject, Py, PyExact, PyObject, PyObjectRef, PyPayload, PyRef, PyRefExact, PyResult, 4 | PyWeakRef, 5 | }, 6 | vm::{Context, Interpreter, Settings, VirtualMachine}, 7 | }; 8 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsSuperfluous_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsXml_c14nPrefixQname.xml: -------------------------------------------------------------------------------- 1 | 2 | data 3 | -------------------------------------------------------------------------------- /benches/microbenchmarks/complex_class.py: -------------------------------------------------------------------------------- 1 | class Foo: 2 | ABC = 1 3 | 4 | def __init__(self): 5 | super().__init__() 6 | 7 | def bar(self): 8 | pass 9 | 10 | @classmethod 11 | def bar_2(cls): 12 | pass 13 | -------------------------------------------------------------------------------- /compiler/ast/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod ast_gen; 2 | mod constant; 3 | #[cfg(feature = "fold")] 4 | mod fold_helpers; 5 | mod impls; 6 | #[cfg(feature = "unparse")] 7 | mod unparse; 8 | 9 | pub use ast_gen::*; 10 | 11 | pub type Suite = Vec>; 12 | -------------------------------------------------------------------------------- /vm/Lib/README.md: -------------------------------------------------------------------------------- 1 | # Frozen Python modules 2 | 3 | A collection of Python modules frozen into the VM at compile time. 4 | 5 | See the comments in [`frozen.rs`](../src/frozen.rs) for explanations of the 6 | different files and subdirectories in this directory. 7 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inC14N2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | A B 4 | 5 | A 6 | 7 | B 8 | A B 9 | C 10 | 11 | 12 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsSort_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /vm/src/object/mod.rs: -------------------------------------------------------------------------------- 1 | mod core; 2 | mod ext; 3 | mod payload; 4 | mod traverse; 5 | mod traverse_object; 6 | 7 | pub use self::core::*; 8 | pub use self::ext::*; 9 | pub use self::payload::*; 10 | pub use traverse::{MaybeTraverse, Traverse, TraverseFn}; 11 | -------------------------------------------------------------------------------- /Lib/test/test_ctypes.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from test.support.import_helper import import_module 3 | 4 | 5 | ctypes_test = import_module('ctypes.test') 6 | 7 | load_tests = ctypes_test.load_tests 8 | 9 | if __name__ == "__main__": 10 | unittest.main() 11 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsPushdown_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_types.py: -------------------------------------------------------------------------------- 1 | import types 2 | 3 | from testutils import assert_raises 4 | 5 | ns = types.SimpleNamespace(a=2, b='Rust') 6 | 7 | assert ns.a == 2 8 | assert ns.b == "Rust" 9 | with assert_raises(AttributeError): 10 | _ = ns.c 11 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_comment.py: -------------------------------------------------------------------------------- 1 | 2 | # Snippet to demo comment handling... 3 | 4 | 5 | def foo(): 6 | a = [] 7 | 8 | # This empty comment below manifests a bug: 9 | # 10 | if len(a) > 2: 11 | a.append(2) 12 | return a 13 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_literal.py: -------------------------------------------------------------------------------- 1 | # Integer literals 2 | assert 0b101010 == 42 3 | assert 0B101010 == 42 4 | assert 0o777 == 511 5 | assert 0O777 == 511 6 | assert 0xcafebabe == 3405691582 7 | assert 0Xcafebabe == 3405691582 8 | assert 0xCAFEBABE == 3405691582 9 | -------------------------------------------------------------------------------- /wasm/demo/snippets/fibonacci.py: -------------------------------------------------------------------------------- 1 | n1 = 0 2 | n2 = 1 3 | count = 0 4 | until = 10 5 | 6 | print(f"These are the first {until} numbers in the Fibonacci sequence:") 7 | 8 | while count < until: 9 | print(n1) 10 | n1, n2 = n2, n1 + n2 11 | count += 1 12 | -------------------------------------------------------------------------------- /Lib/test/ann_module5.py: -------------------------------------------------------------------------------- 1 | # Used by test_typing to verify that Final wrapped in ForwardRef works. 2 | 3 | from __future__ import annotations 4 | 5 | from typing import Final 6 | 7 | name: Final[str] = "final" 8 | 9 | class MyClass: 10 | value: Final = 3000 11 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future5.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | from __future__ import nested_scopes 3 | import foo 4 | from __future__ import nested_scopes 5 | 6 | 7 | def f(x): 8 | def g(y): 9 | return x + y 10 | return g 11 | 12 | result = f(2)(4) 13 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N2_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | A B 4 | 5 | A 6 | 7 | B 8 | A B 9 | C 10 | 11 | -------------------------------------------------------------------------------- /Lib/test/badsyntax_future7.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | 3 | from __future__ import nested_scopes; import string; from __future__ import \ 4 | nested_scopes 5 | 6 | def f(x): 7 | def g(y): 8 | return x + y 9 | return g 10 | 11 | result = f(2)(4) 12 | -------------------------------------------------------------------------------- /extra_tests/snippets/name.py: -------------------------------------------------------------------------------- 1 | #when name.py is run __name__ should equal to __main__ 2 | assert __name__ == "__main__" 3 | 4 | from import_name import import_func 5 | 6 | #__name__ should be set to import_func 7 | import_func() 8 | 9 | assert __name__ == "__main__" 10 | -------------------------------------------------------------------------------- /scripts/update_asdl.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | cd "$(dirname "$(dirname "$0")")" 5 | 6 | python compiler/ast/asdl_rs.py -D compiler/ast/src/ast_gen.rs -M vm/src/stdlib/ast/gen.rs compiler/ast/Python.asdl 7 | rustfmt compiler/ast/src/ast_gen.rs vm/src/stdlib/ast/gen.rs 8 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsPushdown_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.2.10.py: -------------------------------------------------------------------------------- 1 | word = 'Python' 2 | assert 'P' == word[0] # character in position 0 3 | assert 'n' == word[5] # character in position 5 4 | assert 'n' == word[-1] # last character 5 | assert 'o' == word[-2] # second-last character 6 | assert 'P' == word[-6] 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_xdrlib.py: -------------------------------------------------------------------------------- 1 | # This probably will be superceeded by the python unittests when that works. 2 | 3 | import xdrlib 4 | 5 | p = xdrlib.Packer() 6 | p.pack_int(1337) 7 | 8 | d = p.get_buffer() 9 | 10 | print(d) 11 | 12 | # assert d == b'\x00\x00\x059' 13 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsContent_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | xsd:string 3 | /soap-env:body/child::b:foo[@att1 != "c:val" and @att2 != 'xsd:string'] 4 | -------------------------------------------------------------------------------- /extra_tests/benchmarks/perf_fib.py: -------------------------------------------------------------------------------- 1 | def fib(n): 2 | a = 1 3 | b = 1 4 | for _ in range(n - 1): 5 | temp = b 6 | b = a + b 7 | a = temp 8 | 9 | return b 10 | 11 | print(fib(1)) 12 | print(fib(2)) 13 | print(fib(3)) 14 | print(fib(4)) 15 | print(fib(5)) -------------------------------------------------------------------------------- /Lib/test/test_future4.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals 2 | import unittest 3 | 4 | 5 | class Tests(unittest.TestCase): 6 | def test_unicode_literals(self): 7 | self.assertIsInstance("literal", str) 8 | 9 | 10 | if __name__ == "__main__": 11 | unittest.main() 12 | -------------------------------------------------------------------------------- /vm/src/convert/into_object.rs: -------------------------------------------------------------------------------- 1 | use crate::PyObjectRef; 2 | 3 | pub trait IntoObject 4 | where 5 | Self: Into, 6 | { 7 | fn into_object(self) -> PyObjectRef { 8 | self.into() 9 | } 10 | } 11 | 12 | impl IntoObject for T where T: Into {} 13 | -------------------------------------------------------------------------------- /Lib/test/test_longexp.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | class LongExpText(unittest.TestCase): 4 | def test_longexp(self): 5 | REPS = 65580 6 | l = eval("[" + "2," * REPS + "]") 7 | self.assertEqual(len(l), REPS) 8 | 9 | if __name__ == "__main__": 10 | unittest.main() 11 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nTrim.xml: -------------------------------------------------------------------------------- 1 | 2 | true 3 | 4 | 5 | -------------------------------------------------------------------------------- /Lib/xml/parsers/expat.py: -------------------------------------------------------------------------------- 1 | """Interface to the Expat non-validating XML parser.""" 2 | import sys 3 | 4 | from pyexpat import * 5 | 6 | # provide pyexpat submodules as xml.parsers.expat submodules 7 | sys.modules['xml.parsers.expat.model'] = model 8 | sys.modules['xml.parsers.expat.errors'] = errors 9 | -------------------------------------------------------------------------------- /Lib/test/future_test1.py: -------------------------------------------------------------------------------- 1 | """This is a test""" 2 | 3 | # Import the name nested_scopes twice to trigger SF bug #407394 (regression). 4 | from __future__ import nested_scopes, nested_scopes 5 | 6 | def f(x): 7 | def g(y): 8 | return x + y 9 | return g 10 | 11 | result = f(2)(4) 12 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/data/valid/array/array-subtables.json: -------------------------------------------------------------------------------- 1 | {"arr": 2 | {"type":"array","value": 3 | [ 4 | {"subtab": 5 | {"val": {"type":"integer","value":"1"} 6 | } 7 | }, 8 | {"subtab": {"val": {"type":"integer","value":"2"}}} 9 | ] 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nComment.xml: -------------------------------------------------------------------------------- 1 | 2 | true 3 | 4 | 5 | -------------------------------------------------------------------------------- /benches/microbenchmarks/exception_context.py: -------------------------------------------------------------------------------- 1 | from contextlib import contextmanager 2 | 3 | @contextmanager 4 | def try_catch(*args, **kwargs): 5 | try: 6 | yield 7 | except RuntimeError: 8 | pass 9 | 10 | # --- 11 | 12 | with try_catch(): 13 | raise RuntimeError() 14 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/stubs.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class fake_filesystem_unittest: 5 | """ 6 | Stubbed version of the pyfakefs module 7 | """ 8 | class TestCase(unittest.TestCase): 9 | def setUpPyfakefs(self): 10 | self.skipTest("pyfakefs not available") 11 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | sequential 3 | 4 | 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_locals.py: -------------------------------------------------------------------------------- 1 | 2 | a = 5 3 | b = 6 4 | 5 | loc = locals() 6 | 7 | assert loc['a'] == 5 8 | assert loc['b'] == 6 9 | 10 | def f(): 11 | c = 4 12 | a = 7 13 | 14 | loc = locals() 15 | 16 | assert loc['a'] == 4 17 | assert loc['c'] == 7 18 | assert not 'b' in loc 19 | 20 | -------------------------------------------------------------------------------- /scripts/redox/comment-cargo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cargo=${1:-Cargo.toml} 6 | 7 | tmpfile=$(mktemp) 8 | 9 | awk ' 10 | /REDOX START/{redox=1; print; next} 11 | /REDOX END/{redox=0} 12 | {if (redox) print "#", $0; else print} 13 | ' "$cargo" >"$tmpfile" 14 | 15 | mv "$tmpfile" "$cargo" 16 | -------------------------------------------------------------------------------- /scripts/redox/uncomment-cargo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | cargo=${1:-Cargo.toml} 6 | 7 | tmpfile=$(mktemp) 8 | 9 | awk ' 10 | /REDOX START/{redox=1; print; next} 11 | /REDOX END/{redox=0} 12 | {if (redox) sub(/^#\s*/, ""); print} 13 | ' "$cargo" >"$tmpfile" 14 | 15 | mv "$tmpfile" "$cargo" 16 | -------------------------------------------------------------------------------- /Lib/__hello__.py: -------------------------------------------------------------------------------- 1 | initialized = True 2 | 3 | class TestFrozenUtf8_1: 4 | """\u00b6""" 5 | 6 | class TestFrozenUtf8_2: 7 | """\u03c0""" 8 | 9 | class TestFrozenUtf8_4: 10 | """\U0001f600""" 11 | 12 | def main(): 13 | print("Hello world!") 14 | 15 | if __name__ == '__main__': 16 | main() 17 | -------------------------------------------------------------------------------- /Lib/distutils/__init__.py: -------------------------------------------------------------------------------- 1 | """distutils 2 | 3 | The main package for the Python Module Distribution Utilities. Normally 4 | used from a setup script as 5 | 6 | from distutils.core import setup 7 | 8 | setup (...) 9 | """ 10 | 11 | import sys 12 | 13 | __version__ = sys.version[:sys.version.index(' ')] 14 | -------------------------------------------------------------------------------- /Lib/tomllib/_types.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # SPDX-FileCopyrightText: 2021 Taneli Hukkinen 3 | # Licensed to PSF under a Contributor Agreement. 4 | 5 | from typing import Any, Callable, Tuple 6 | 7 | # Type annotations 8 | ParseFloat = Callable[[str], Any] 9 | Key = Tuple[str, ...] 10 | Pos = int 11 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_logging.py: -------------------------------------------------------------------------------- 1 | 2 | import io 3 | import sys 4 | 5 | f = io.StringIO() 6 | sys.stderr = f 7 | 8 | import logging 9 | 10 | logging.error('WOOT') 11 | logging.warning('WARN') 12 | 13 | res = f.getvalue() 14 | 15 | assert 'WOOT' in res 16 | assert 'WARN' in res 17 | print(res) 18 | 19 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_non_utf8.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | 4 | from testutils import assert_raises 5 | 6 | dir_path = os.path.dirname(os.path.realpath(__file__)) 7 | 8 | with assert_raises(ValueError): 9 | with open(os.path.join(dir_path , "non_utf8.txt")) as f: 10 | eval(f.read()) 11 | -------------------------------------------------------------------------------- /Lib/test/test_unittest.py: -------------------------------------------------------------------------------- 1 | import unittest.test 2 | 3 | from test import support 4 | 5 | 6 | def load_tests(*_): 7 | # used by unittest 8 | return unittest.test.suite() 9 | 10 | 11 | def tearDownModule(): 12 | support.reap_children() 13 | 14 | 15 | if __name__ == "__main__": 16 | unittest.main() 17 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_indent.py: -------------------------------------------------------------------------------- 1 | # WARNING! This file contains mixed tabs and spaces 2 | # (because that's what it is testing) 3 | 4 | def weird_indentation(): 5 | return_value = "hi" 6 | if False: 7 | return return_value 8 | return "hi" 9 | 10 | assert weird_indentation() == "hi" 11 | 12 | -------------------------------------------------------------------------------- /wasm/example/src/index.js: -------------------------------------------------------------------------------- 1 | // A dependency graph that contains any wasm must all be imported 2 | // asynchronously. This `index.js` file does the single async import, so 3 | // that no one else needs to worry about it again. 4 | import('./main.js').catch((e) => { 5 | console.error('Error importing `main.js`:', e); 6 | }); 7 | -------------------------------------------------------------------------------- /Lib/test/subprocessdata/qgrep.py: -------------------------------------------------------------------------------- 1 | """When called with a single argument, simulated fgrep with a single 2 | argument and no options.""" 3 | 4 | import sys 5 | 6 | if __name__ == "__main__": 7 | pattern = sys.argv[1] 8 | for line in sys.stdin: 9 | if pattern in line: 10 | sys.stdout.write(line) 11 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inC14N1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | Hello, world! 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /scripts/redox/recipe.sh: -------------------------------------------------------------------------------- 1 | GIT=https://github.com/RustPython/RustPython 2 | BRANCH=redox-release 3 | CARGOFLAGS=--no-default-features 4 | export BUILDTIME_RUSTPYTHONPATH=/lib/rustpython/ 5 | 6 | function recipe_stage() { 7 | dest="$(realpath "$1")" 8 | mkdir -pv "$dest/lib/" 9 | cp -r Lib "$dest/lib/rustpython" 10 | } 11 | -------------------------------------------------------------------------------- /scripts/release-wapm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | cd "$(dirname "$(dirname "$0")")" 5 | 6 | FEATURES_FOR_WAPM=(stdlib zlib) 7 | 8 | export BUILDTIME_RUSTPYTHONPATH="/lib/rustpython" 9 | 10 | cargo build --release --target wasm32-wasi --no-default-features --features="${FEATURES_FOR_WAPM[*]}" 11 | 12 | wapm publish 13 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | # 2 | # This list is used by git-shortlog to aggregate contributions. It is 3 | # necessary when either the author's full name is not always written 4 | # the same way, and/or the same author contributes from different 5 | # email addresses. 6 | # 7 | 8 | Noa <33094578+coolreader18@users.noreply.github.com> 9 | -------------------------------------------------------------------------------- /Lib/struct.py: -------------------------------------------------------------------------------- 1 | __all__ = [ 2 | # Functions 3 | 'calcsize', 'pack', 'pack_into', 'unpack', 'unpack_from', 4 | 'iter_unpack', 5 | 6 | # Classes 7 | 'Struct', 8 | 9 | # Exceptions 10 | 'error' 11 | ] 12 | 13 | from _struct import * 14 | from _struct import _clearcache 15 | from _struct import __doc__ 16 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsContent_c14nQnameElem.xml: -------------------------------------------------------------------------------- 1 | 2 | xsd:string 3 | /soap-env:body/child::b:foo[@att1 != "c:val" and @att2 != 'xsd:string'] 4 | -------------------------------------------------------------------------------- /extra_tests/snippets/imghdrdata/python.xbm: -------------------------------------------------------------------------------- 1 | #define python_width 16 2 | #define python_height 16 3 | static char python_bits[] = { 4 | 0xDF, 0xFE, 0x8F, 0xFD, 0x5F, 0xFB, 0xAB, 0xFE, 0xB5, 0x8D, 0xDA, 0x8F, 5 | 0xA5, 0x86, 0xFA, 0x83, 0x1A, 0x80, 0x0D, 0x80, 0x0D, 0x80, 0x0F, 0xE0, 6 | 0x0F, 0xF8, 0x0F, 0xF8, 0x0F, 0xFC, 0xFF, 0xFF, }; 7 | -------------------------------------------------------------------------------- /Lib/ctypes/macholib/README.ctypes: -------------------------------------------------------------------------------- 1 | Files in this directory come from Bob Ippolito's py2app. 2 | 3 | License: Any components of the py2app suite may be distributed under 4 | the MIT or PSF open source licenses. 5 | 6 | This is version 1.0, SVN revision 789, from 2006/01/25. 7 | The main repository is http://svn.red-bean.com/bob/macholib/trunk/macholib/ -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_chr.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | assert "a" == chr(97) 4 | assert "é" == chr(233) 5 | assert "🤡" == chr(129313) 6 | 7 | assert_raises(TypeError, chr, _msg='chr() takes exactly one argument (0 given)') 8 | assert_raises(ValueError, chr, 0x110005, _msg='ValueError: chr() arg not in range(0x110000)') 9 | -------------------------------------------------------------------------------- /vm/src/convert/mod.rs: -------------------------------------------------------------------------------- 1 | mod into_object; 2 | mod to_pyobject; 3 | mod transmute_from; 4 | mod try_from; 5 | 6 | pub use into_object::IntoObject; 7 | pub use to_pyobject::{IntoPyException, ToPyException, ToPyObject, ToPyResult}; 8 | pub use transmute_from::TransmuteFromObject; 9 | pub use try_from::{TryFromBorrowedObject, TryFromObject}; 10 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | **/target/ 2 | **/*.rs.bk 3 | **/*.bytecode 4 | **/__pycache__/* 5 | **/*.pytest_cache 6 | .*sw* 7 | .repl_history.txt 8 | .vscode 9 | wasm-pack.log 10 | .idea/ 11 | extra_tests/snippets/resources 12 | 13 | flame-graph.html 14 | flame.txt 15 | flamescope.json 16 | 17 | **/node_modules/ 18 | wasm/**/dist/ 19 | wasm/lib/pkg/ 20 | -------------------------------------------------------------------------------- /extra_tests/snippets/protocol_iternext.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | ls = [1, 2, 3] 4 | 5 | i = iter(ls) 6 | assert i.__next__() == 1 7 | assert i.__next__() == 2 8 | assert next(i) == 3 9 | 10 | assert next(i, 'w00t') == 'w00t' 11 | 12 | s = '你好' 13 | i = iter(s) 14 | i.__setstate__(1) 15 | assert i.__next__() == '好' 16 | assert i.__reduce__()[2] == 2 17 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nQnameElem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/example_fizzbuzz.py: -------------------------------------------------------------------------------- 1 | def fizzbuzz(n): 2 | if n % 3 == 0 and n % 5 == 0: 3 | return "FizzBuzz" 4 | elif n % 3 == 0: 5 | return "Fizz" 6 | elif n % 5 == 0: 7 | return "Buzz" 8 | else: 9 | return str(n) 10 | 11 | n = 1 12 | while n < 10: 13 | print(fizzbuzz(n)) 14 | n += 1 15 | -------------------------------------------------------------------------------- /wasm/example/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | entry: './src/index.js', 5 | mode: 'development', 6 | output: { 7 | path: path.join(__dirname, 'dist'), 8 | filename: 'app.js', 9 | publicPath: '/dist/', 10 | }, 11 | devtool: 'cheap-module-eval-source-map', 12 | }; 13 | -------------------------------------------------------------------------------- /extra_tests/snippets/recursion.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | class Foo(object): 4 | pass 5 | 6 | Foo.__repr__ = Foo.__str__ 7 | 8 | foo = Foo() 9 | # Since the default __str__ implementation calls __repr__ and __repr__ is 10 | # actually __str__, str(foo) should raise a RecursionError. 11 | assert_raises(RecursionError, str, foo) 12 | -------------------------------------------------------------------------------- /wasm/demo/snippets/fetch.py: -------------------------------------------------------------------------------- 1 | from browser import fetch 2 | 3 | def fetch_handler(res): 4 | print(f"headers: {res['headers']}") 5 | 6 | fetch( 7 | "https://httpbin.org/get", 8 | response_format="json", 9 | headers={ 10 | "X-Header-Thing": "rustpython is neat!" 11 | }, 12 | ).then(fetch_handler, lambda err: print(f"error: {err}")) 13 | -------------------------------------------------------------------------------- /Lib/test/ann_module7.py: -------------------------------------------------------------------------------- 1 | # Tests class have ``__text_signature__`` 2 | 3 | from __future__ import annotations 4 | 5 | DEFAULT_BUFFER_SIZE = 8192 6 | 7 | class BufferedReader(object): 8 | """BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n--\n\n 9 | Create a new buffered reader using the given readable raw IO object. 10 | """ 11 | pass 12 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_ascii.py: -------------------------------------------------------------------------------- 1 | assert ascii('hello world') == "'hello world'" 2 | assert ascii('안녕 세상') == "'\\uc548\\ub155 \\uc138\\uc0c1'" 3 | assert ascii('안녕 RustPython') == "'\\uc548\\ub155 RustPython'" 4 | assert ascii(5) == '5' 5 | assert ascii(chr(0x10001)) == "'\\U00010001'" 6 | assert ascii(chr(0x9999)) == "'\\u9999'" 7 | assert ascii(chr(0x0A)) == "'\\n'" -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /*/target 3 | **/*.rs.bk 4 | **/*.bytecode 5 | __pycache__ 6 | **/*.pytest_cache 7 | .*sw* 8 | .repl_history.txt 9 | .vscode 10 | wasm-pack.log 11 | .idea/ 12 | 13 | flame-graph.html 14 | flame.txt 15 | flamescope.json 16 | /wapm.lock 17 | /wapm_packages 18 | /.cargo/config 19 | 20 | extra_tests/snippets/resources 21 | extra_tests/not_impl.py 22 | -------------------------------------------------------------------------------- /Lib/distutils/README: -------------------------------------------------------------------------------- 1 | This directory contains the Distutils package. 2 | 3 | There's a full documentation available at: 4 | 5 | http://docs.python.org/distutils/ 6 | 7 | The Distutils-SIG web page is also a good starting point: 8 | 9 | http://www.python.org/sigs/distutils-sig/ 10 | 11 | WARNING : Distutils must remain compatible with 2.3 12 | 13 | $Id$ 14 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N3_c14nTrim.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Lib/tomllib/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # SPDX-FileCopyrightText: 2021 Taneli Hukkinen 3 | # Licensed to PSF under a Contributor Agreement. 4 | 5 | __all__ = ("loads", "load", "TOMLDecodeError") 6 | 7 | from ._parser import TOMLDecodeError, load, loads 8 | 9 | # Pretend this exception was created here. 10 | TOMLDecodeError.__module__ = __name__ 11 | -------------------------------------------------------------------------------- /Dockerfile.bin: -------------------------------------------------------------------------------- 1 | FROM rust:latest as rust 2 | 3 | WORKDIR /rustpython 4 | 5 | COPY . . 6 | 7 | RUN cargo build --release 8 | 9 | FROM debian:stable-slim 10 | 11 | COPY --from=rust /rustpython/target/release/rustpython /usr/bin 12 | COPY --from=rust /rustpython/Lib /usr/lib/rustpython 13 | ENV RUSTPYTHONPATH /usr/lib/rustpython 14 | 15 | ENTRYPOINT [ "rustpython" ] 16 | -------------------------------------------------------------------------------- /Lib/test/test_json/test_default.py: -------------------------------------------------------------------------------- 1 | from test.test_json import PyTest, CTest 2 | 3 | 4 | class TestDefault: 5 | def test_default(self): 6 | self.assertEqual( 7 | self.dumps(type, default=repr), 8 | self.dumps(repr(type))) 9 | 10 | 11 | class TestPyDefault(TestDefault, PyTest): pass 12 | class TestCDefault(TestDefault, CTest): pass 13 | -------------------------------------------------------------------------------- /Lib/unittest/test/testmock/support.py: -------------------------------------------------------------------------------- 1 | target = {'foo': 'FOO'} 2 | 3 | 4 | def is_instance(obj, klass): 5 | """Version of is_instance that doesn't access __class__""" 6 | return issubclass(type(obj), klass) 7 | 8 | 9 | class SomeClass(object): 10 | class_attribute = None 11 | 12 | def wibble(self): pass 13 | 14 | 15 | class X(object): 16 | pass 17 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_all.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | from testutils import TestFailingBool, TestFailingIter 3 | 4 | assert all([True]) 5 | assert not all([False]) 6 | assert all([]) 7 | assert not all([False, TestFailingBool()]) 8 | 9 | assert_raises(RuntimeError, all, TestFailingIter()) 10 | assert_raises(RuntimeError, all, [TestFailingBool()]) 11 | -------------------------------------------------------------------------------- /stdlib/src/md5.rs: -------------------------------------------------------------------------------- 1 | pub(crate) use _md5::make_module; 2 | 3 | #[pymodule] 4 | mod _md5 { 5 | use crate::hashlib::_hashlib::{local_md5, HashArgs}; 6 | use crate::vm::{PyPayload, PyResult, VirtualMachine}; 7 | 8 | #[pyfunction] 9 | fn md5(args: HashArgs, vm: &VirtualMachine) -> PyResult { 10 | Ok(local_md5(args).into_pyobject(vm)) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lib/decimal.py: -------------------------------------------------------------------------------- 1 | 2 | try: 3 | from _decimal import * 4 | from _decimal import __doc__ 5 | from _decimal import __version__ 6 | from _decimal import __libmpdec_version__ 7 | except ImportError: 8 | from _pydecimal import * 9 | from _pydecimal import __doc__ 10 | from _pydecimal import __version__ 11 | from _pydecimal import __libmpdec_version__ 12 | -------------------------------------------------------------------------------- /extra_tests/snippets/protocol_callable.py: -------------------------------------------------------------------------------- 1 | class Callable(): 2 | def __init__(self): 3 | self.count = 0 4 | 5 | def __call__(self): 6 | self.count += 1 7 | return self.count 8 | 9 | c = Callable() 10 | assert 1 == c() 11 | assert 2 == c() 12 | 13 | class Inherited(Callable): 14 | pass 15 | 16 | i = Inherited() 17 | 18 | assert 1 == i() 19 | -------------------------------------------------------------------------------- /stdlib/src/sha1.rs: -------------------------------------------------------------------------------- 1 | pub(crate) use _sha1::make_module; 2 | 3 | #[pymodule] 4 | mod _sha1 { 5 | use crate::hashlib::_hashlib::{local_sha1, HashArgs}; 6 | use crate::vm::{PyPayload, PyResult, VirtualMachine}; 7 | 8 | #[pyfunction] 9 | fn sha1(args: HashArgs, vm: &VirtualMachine) -> PyResult { 10 | Ok(local_sha1(args).into_pyobject(vm)) 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nQname.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_any.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | from testutils import TestFailingBool, TestFailingIter 3 | 4 | assert any([True]) 5 | assert not any([False]) 6 | assert not any([]) 7 | assert any([True, TestFailingBool()]) 8 | 9 | assert_raises(RuntimeError, lambda: any(TestFailingIter())) 10 | assert_raises(RuntimeError, lambda: any([TestFailingBool()])) 11 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.2.1.py: -------------------------------------------------------------------------------- 1 | assert 'spam eggs' == 'spam eggs' # single quotes 2 | assert "doesn't" == 'doesn\'t' # use \' to escape the single quote... 3 | assert "doesn't" == "doesn't" # ...or use double quotes instead 4 | assert '"Yes," he said.' == '"Yes," he said.' 5 | assert '"Yes," he said.' == "\"Yes,\" he said." 6 | assert '"Isn\'t," she said.' == '"Isn\'t," she said.' 7 | 8 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_short_circuit_evaluations.py: -------------------------------------------------------------------------------- 1 | 2 | # Test various cases of short circuit evaluation: 3 | 4 | run = 1 5 | timeTaken = 33 6 | r = (11, 22, run, run != 1 and "s" or "", timeTaken) 7 | print(r) 8 | assert r == (11, 22, 1, '', 33) 9 | 10 | 11 | run = 0 12 | r = (11, 22, run, run != 1 and "s" or "", timeTaken) 13 | print(r) 14 | assert r == (11, 22, 0, 's', 33) 15 | 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | Lib/** linguist-vendored 2 | Cargo.lock linguist-generated -merge 3 | *.snap linguist-generated -merge 4 | ast/src/ast_gen.rs linguist-generated -merge 5 | vm/src/stdlib/ast/gen.rs linguist-generated -merge 6 | compiler/parser/python.lalrpop text eol=LF 7 | Lib/*.py text working-tree-encoding=UTF-8 eol=LF 8 | **/*.rs text working-tree-encoding=UTF-8 eol=LF 9 | -------------------------------------------------------------------------------- /Lib/importlib/readers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Compatibility shim for .resources.readers as found on Python 3.10. 3 | 4 | Consumers that can rely on Python 3.11 should use the other 5 | module directly. 6 | """ 7 | 8 | from .resources.readers import ( 9 | FileReader, ZipReader, MultiplexedPath, NamespaceReader, 10 | ) 11 | 12 | __all__ = ['FileReader', 'ZipReader', 'MultiplexedPath', 'NamespaceReader'] 13 | -------------------------------------------------------------------------------- /Lib/test/tokenize_tests-no-coding-cookie-and-utf8-bom-sig-only.txt: -------------------------------------------------------------------------------- 1 | # IMPORTANT: this file has the utf-8 BOM signature '\xef\xbb\xbf' 2 | # at the start of it. Make sure this is preserved if any changes 3 | # are made! 4 | 5 | # Arbitrary encoded utf-8 text (stolen from test_doctest2.py). 6 | x = 'ЉЊЈЁЂ' 7 | def y(): 8 | """ 9 | And again in a comment. ЉЊЈЁЂ 10 | """ 11 | pass 12 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsContent_c14nPrefixQnameXpathElem.xml: -------------------------------------------------------------------------------- 1 | 2 | n1:string 3 | /n3:body/child::n2:foo[@att1 != "c:val" and @att2 != 'xsd:string'] 4 | -------------------------------------------------------------------------------- /compiler/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython-compiler" 3 | version = "0.2.0" 4 | description = "A usability wrapper around rustpython-parser and rustpython-compiler-core" 5 | authors = ["RustPython Team"] 6 | edition = "2021" 7 | 8 | [dependencies] 9 | rustpython-compiler-core = { path = "core" } 10 | rustpython-codegen = { path = "codegen" } 11 | rustpython-parser = { path = "parser" } 12 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inC14N5.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | ]> 8 | 9 | &ent1;, &ent2;! 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/expat224_utf8_bug.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inNsContent_c14nQnameXpathElem.xml: -------------------------------------------------------------------------------- 1 | 2 | xsd:string 3 | /soap-env:body/child::b:foo[@att1 != "c:val" and @att2 != 'xsd:string'] 4 | -------------------------------------------------------------------------------- /compiler/core/src/lib.rs: -------------------------------------------------------------------------------- 1 | #![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")] 2 | #![doc(html_root_url = "https://docs.rs/rustpython-compiler-core/")] 3 | 4 | mod bytecode; 5 | mod error; 6 | mod location; 7 | pub mod marshal; 8 | mod mode; 9 | 10 | pub use bytecode::*; 11 | pub use error::BaseError; 12 | pub use location::Location; 13 | pub use mode::Mode; 14 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inNsContent.xml: -------------------------------------------------------------------------------- 1 | 2 | xsd:string 3 | /soap-env:body/child::b:foo[@att1 != "c:val" and @att2 != 'xsd:string'] 4 | 5 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_divmod.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | assert divmod(11, 3) == (3, 2) 4 | assert divmod(8,11) == (0, 8) 5 | assert divmod(0.873, 0.252) == (3.0, 0.11699999999999999) 6 | assert divmod(-86340, 86400) == (-1, 60) 7 | 8 | assert_raises(ZeroDivisionError, divmod, 5, 0, _msg='divmod by zero') 9 | assert_raises(ZeroDivisionError, divmod, 5.0, 0.0, _msg='divmod by zero') 10 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_termios.py: -------------------------------------------------------------------------------- 1 | def _test_termios(): 2 | # These tests are in a function so we can only run them if termios is available 3 | assert termios.error.__module__ == "termios" 4 | assert termios.error.__name__ == "error" 5 | 6 | 7 | try: 8 | import termios 9 | except ImportError: 10 | # Not all platforms have termios, noop 11 | pass 12 | else: 13 | _test_termios() 14 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_type_mro.py: -------------------------------------------------------------------------------- 1 | class X(): 2 | pass 3 | 4 | class Y(): 5 | pass 6 | 7 | class A(X, Y): 8 | pass 9 | 10 | assert (A, X, Y, object) == A.__mro__ 11 | 12 | class B(X, Y): 13 | pass 14 | 15 | assert (B, X, Y, object) == B.__mro__ 16 | 17 | class C(A, B): 18 | pass 19 | 20 | assert (C, A, B, X, Y, object) == C.__mro__ 21 | 22 | assert type.__mro__ == (type, object) 23 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_type_hint.py: -------------------------------------------------------------------------------- 1 | 2 | # See also: https://github.com/RustPython/RustPython/issues/587 3 | 4 | def curry(foo: int, bla: int =2) -> float: 5 | return foo * 3.1415926 * bla 6 | 7 | assert curry(2) > 10 8 | 9 | print(curry.__annotations__) 10 | assert curry.__annotations__['foo'] is int 11 | assert curry.__annotations__['return'] is float 12 | assert curry.__annotations__['bla'] is int 13 | -------------------------------------------------------------------------------- /Lib/test/tokenize_tests-utf8-coding-cookie-and-utf8-bom-sig.txt: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # IMPORTANT: this file has the utf-8 BOM signature '\xef\xbb\xbf' 3 | # at the start of it. Make sure this is preserved if any changes 4 | # are made! 5 | 6 | # Arbitrary encoded utf-8 text (stolen from test_doctest2.py). 7 | x = 'ЉЊЈЁЂ' 8 | def y(): 9 | """ 10 | And again in a comment. ЉЊЈЁЂ 11 | """ 12 | pass 13 | -------------------------------------------------------------------------------- /extra_tests/snippets/3.1.2.13.py: -------------------------------------------------------------------------------- 1 | word = "Python" 2 | 3 | assert "Python" == word[:2] + word[2:] 4 | assert "Python" == word[:4] + word[4:] 5 | 6 | assert "Py" == word[:2] 7 | assert "on" == word[4:] 8 | assert "on" == word[-2:] 9 | assert "Py" == word[:-4] 10 | # assert "Py" == word[::2] 11 | 12 | assert "Pto" == word[::2] 13 | assert "yhn" == word[1::2] 14 | assert "Pt" == word[:4:2] 15 | assert "yh" == word[1:4:2] 16 | -------------------------------------------------------------------------------- /wasm/example/src/main.py: -------------------------------------------------------------------------------- 1 | from browser import fetch, alert 2 | 3 | def fetch_handler(repos): 4 | star_sum = 0 5 | for repo in repos: 6 | star_sum += repo['stars'] 7 | alert(f'Average github trending star count: {star_sum / len(repos)}') 8 | 9 | fetch( 10 | 'https://github-trending-api.now.sh/repositories', 11 | response_format='json', 12 | ).then(fetch_handler, lambda err: alert(f"Error: {err}")) -------------------------------------------------------------------------------- /wasm/example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | RustPython Basic Example 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Lib/importlib/simple.py: -------------------------------------------------------------------------------- 1 | """ 2 | Compatibility shim for .resources.simple as found on Python 3.10. 3 | 4 | Consumers that can rely on Python 3.11 should use the other 5 | module directly. 6 | """ 7 | 8 | from .resources.simple import ( 9 | SimpleReader, ResourceHandle, ResourceContainer, TraversableReader, 10 | ) 11 | 12 | __all__ = [ 13 | 'SimpleReader', 'ResourceHandle', 'ResourceContainer', 'TraversableReader', 14 | ] 15 | -------------------------------------------------------------------------------- /wasm/tests/test_inject_module.py: -------------------------------------------------------------------------------- 1 | def test_inject_module_basic(wdriver): 2 | wdriver.execute_script( 3 | """ 4 | const vm = rp.vmStore.init("vm") 5 | vm.injectModule( 6 | "mod", 7 | ` 8 | __all__ = ['get_thing'] 9 | def get_thing(): return __thing() 10 | `, 11 | { __thing: () => 1 }, 12 | true 13 | ) 14 | vm.execSingle( 15 | ` 16 | import mod 17 | assert mod.get_thing() == 1 18 | ` 19 | ); 20 | """ 21 | ) 22 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nQnameXpathElem.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lib/test/test_import/data/unwritable/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | class MyMod(object): 4 | __slots__ = ['__builtins__', '__cached__', '__doc__', 5 | '__file__', '__loader__', '__name__', 6 | '__package__', '__path__', '__spec__'] 7 | def __init__(self): 8 | for attr in self.__slots__: 9 | setattr(self, attr, globals()[attr]) 10 | 11 | 12 | sys.modules[__name__] = MyMod() 13 | -------------------------------------------------------------------------------- /common/src/rc.rs: -------------------------------------------------------------------------------- 1 | #[cfg(not(feature = "threading"))] 2 | use std::rc::Rc; 3 | #[cfg(feature = "threading")] 4 | use std::sync::Arc; 5 | 6 | // type aliases instead of newtypes because you can't do `fn method(self: PyRc)` with a 7 | // newtype; requires the arbitrary_self_types unstable feature 8 | 9 | #[cfg(feature = "threading")] 10 | pub type PyRc = Arc; 11 | #[cfg(not(feature = "threading"))] 12 | pub type PyRc = Rc; 13 | -------------------------------------------------------------------------------- /examples/package_embed.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from typing import Any 3 | 4 | __all__ = ["context"] 5 | 6 | 7 | @dataclass 8 | class Context: 9 | name: str 10 | something: Any 11 | 12 | 13 | _context = Context( 14 | name="test name", 15 | something=None, 16 | ) 17 | 18 | 19 | def context() -> Context: 20 | return _context 21 | 22 | 23 | if __name__ == "__main__": 24 | print(context().name) 25 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nPrefixQname.xml: -------------------------------------------------------------------------------- 1 | 2 | sequential 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N4_c14nTrim.xml: -------------------------------------------------------------------------------- 1 | First line 2 | Second line2value>"0" && value<"10" ?"valid":"error"valid -------------------------------------------------------------------------------- /scripts/redox/run-redoxer.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eo pipefail 4 | 5 | cd "$(dirname "$0")" 6 | cd ../.. 7 | 8 | DIR=$(mktemp -d) 9 | 10 | trap 'cd / && rm -rf "$DIR"' EXIT SIGINT 11 | 12 | BUILDTIME_RUSTPYTHONPATH=/root/rustpython-lib redoxer build --release 13 | 14 | cp target/x86_64-unknown-redox/release/rustpython -t "$DIR" 15 | ln -s "$PWD"/Lib "$DIR"/rustpython-lib 16 | 17 | redoxer exec -f "$DIR" -- ./rustpython "$@" 18 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_weakref.py: -------------------------------------------------------------------------------- 1 | from _weakref import ref, proxy 2 | from testutils import assert_raises 3 | 4 | 5 | class X: 6 | pass 7 | 8 | 9 | a = X() 10 | b = ref(a) 11 | 12 | assert callable(b) 13 | assert b() is a 14 | 15 | 16 | class G: 17 | def __init__(self, h): 18 | self.h = h 19 | 20 | 21 | g = G(5) 22 | p = proxy(g) 23 | 24 | assert p.h == 5 25 | 26 | del g 27 | 28 | assert_raises(ReferenceError, lambda: p.h) 29 | -------------------------------------------------------------------------------- /scripts/codecoverage-rustc-wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | get_crate_name() { 4 | while [[ $# -gt 1 ]]; do 5 | case "$1" in 6 | --crate-name) 7 | echo "$2" 8 | return 9 | ;; 10 | esac 11 | shift 12 | done 13 | } 14 | 15 | case $(get_crate_name "$@") in 16 | rustpython_*|rustpython) 17 | EXTRA=(-Cinstrument-coverage) 18 | ;; 19 | 20 | *) EXTRA=() ;; 21 | esac 22 | 23 | exec "$@" "${EXTRA[@]}" 24 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_super.py: -------------------------------------------------------------------------------- 1 | test_super_list = super(list) 2 | assert test_super_list.__self__ is None 3 | assert test_super_list.__self_class__ is None 4 | assert test_super_list.__thisclass__ == list 5 | 6 | 7 | class testA: 8 | a = 1 9 | 10 | 11 | class testB(testA): 12 | b = 1 13 | 14 | 15 | superB = super(testB) 16 | assert superB.__thisclass__ == testB 17 | assert superB.__self_class__ is None 18 | assert superB.__self__ is None 19 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_for.py: -------------------------------------------------------------------------------- 1 | x = 0 2 | for i in [1, 2, 3, 4]: 3 | x += 1 4 | 5 | assert x == 4 6 | 7 | for i in [1, 2, 3]: 8 | x = i + 5 9 | else: 10 | x = 3 11 | 12 | assert x == 3 13 | 14 | y = [] 15 | for x, in [(9,), [2]]: 16 | y.append(x) 17 | 18 | assert y == [9, 2], str(y) 19 | 20 | y = [] 21 | for x, *z in [(9,88,'b'), [2, 'bla'], [None]*4]: 22 | y.append(z) 23 | 24 | assert y == [[88, 'b'], ['bla'], [None]*3], str(y) 25 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_bin.py: -------------------------------------------------------------------------------- 1 | assert bin(0) == '0b0' 2 | assert bin(1) == '0b1' 3 | assert bin(-1) == '-0b1' 4 | assert bin(2**24) == '0b1' + '0' * 24 5 | assert bin(2**24-1) == '0b' + '1' * 24 6 | assert bin(-(2**24)) == '-0b1' + '0' * 24 7 | assert bin(-(2**24-1)) == '-0b' + '1' * 24 8 | 9 | a = 2 ** 65 10 | assert bin(a) == '0b1' + '0' * 65 11 | assert bin(a-1) == '0b' + '1' * 65 12 | assert bin(-(a)) == '-0b1' + '0' * 65 13 | assert bin(-(a-1)) == '-0b' + '1' * 65 14 | -------------------------------------------------------------------------------- /wasm/example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rustpython-wasm-example", 3 | "version": "1.0.0", 4 | "dependencies": { 5 | "rustpython_wasm": "0.1.0-pre-alpha.1" 6 | }, 7 | "devDependencies": { 8 | "raw-loader": "1.0.0", 9 | "webpack": "4.28.2", 10 | "webpack-cli": "^3.1.2" 11 | }, 12 | "scripts": { 13 | "build": "webpack", 14 | "dist": "webpack --mode production" 15 | }, 16 | "license": "MIT" 17 | } 18 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_time.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | import time 4 | 5 | x = time.gmtime(1000) 6 | 7 | assert x.tm_year == 1970 8 | assert x.tm_min == 16 9 | assert x.tm_sec == 40 10 | assert x.tm_isdst == 0 11 | 12 | s = time.strftime('%Y-%m-%d-%H-%M-%S', x) 13 | # print(s) 14 | assert s == '1970-01-01-00-16-40' 15 | 16 | x2 = time.strptime(s, '%Y-%m-%d-%H-%M-%S') 17 | assert x2.tm_min == 16 18 | 19 | s = time.asctime(x) 20 | # print(s) 21 | assert s == 'Thu Jan 1 00:16:40 1970' 22 | 23 | -------------------------------------------------------------------------------- /Lib/test/test_tomllib/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # SPDX-FileCopyrightText: 2021 Taneli Hukkinen 3 | # Licensed to PSF under a Contributor Agreement. 4 | 5 | __all__ = ("tomllib",) 6 | 7 | # By changing this one line, we can run the tests against 8 | # a different module name. 9 | import tomllib 10 | 11 | import os 12 | from test.support import load_package_tests 13 | 14 | def load_tests(*args): 15 | return load_package_tests(os.path.dirname(__file__), *args) 16 | -------------------------------------------------------------------------------- /wasm/demo/snippets/asyncbrowser.py: -------------------------------------------------------------------------------- 1 | import browser 2 | import asyncweb 3 | 4 | async def main(delay): 5 | url = f"https://httpbin.org/delay/{delay}" 6 | print(f"fetching {url}...") 7 | res = await browser.fetch( 8 | url, response_format="json", headers={"X-Header-Thing": "rustpython is neat!"} 9 | ) 10 | print(f"got res from {res['url']}:") 11 | print(res, end="\n\n") 12 | 13 | 14 | for delay in range(3): 15 | asyncweb.run(main(delay)) 16 | print() 17 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_funky.py: -------------------------------------------------------------------------------- 1 | import traceback 2 | 3 | a = 2 4 | b = 2 + 4 if a < 5 else 'boe' 5 | assert b == 6 6 | c = 2 + 4 if a > 5 else 'boe' 7 | assert c == 'boe' 8 | 9 | d = lambda x, y: x > y 10 | assert d(5, 4) 11 | 12 | e = lambda x: 1 if x else 0 13 | assert e(True) == 1 14 | assert e(False) == 0 15 | 16 | try: 17 | a = "aaaa" + \ 18 | "bbbb" 19 | 1/0 20 | except ZeroDivisionError as ex: 21 | tb = traceback.extract_tb(ex.__traceback__) 22 | assert tb[0].lineno == 19 23 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/c14nPrefixQnameXpathElem.xml: -------------------------------------------------------------------------------- 1 | 2 | sequential 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N3_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /wapm.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython" 3 | version = "0.2.0" 4 | description = "A Python-3 (CPython >= 3.5.0) Interpreter written in Rust 🐍 😱 🤘" 5 | license-file = "LICENSE" 6 | readme = "README.md" 7 | repository = "https://github.com/RustPython/RustPython" 8 | 9 | [[module]] 10 | name = "rustpython" 11 | source = "target/wasm32-wasi/release/rustpython.wasm" 12 | abi = "wasi" 13 | 14 | [[command]] 15 | name = "rustpython" 16 | module = "rustpython" 17 | 18 | [fs] 19 | "/lib/rustpython" = "Lib" 20 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "tasks": [ 4 | { 5 | "label": "Build RustPython Debug", 6 | "type": "shell", 7 | "command": "cargo", 8 | "args": [ 9 | "build", 10 | ], 11 | "problemMatcher": [ 12 | "$rustc", 13 | ], 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true, 17 | }, 18 | } 19 | ], 20 | } -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N4_c14nDefault.xml: -------------------------------------------------------------------------------- 1 | 2 | First line 3 | Second line 4 | 2 5 | value>"0" && value<"10" ?"valid":"error" 6 | valid 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_hash.py: -------------------------------------------------------------------------------- 1 | 2 | from testutils import assert_raises 3 | 4 | 5 | class A: 6 | pass 7 | 8 | 9 | assert type(hash(None)) is int 10 | assert type(hash(object())) is int 11 | assert type(hash(A())) is int 12 | assert type(hash(1)) is int 13 | assert type(hash(1.1)) is int 14 | assert type(hash("")) is int 15 | 16 | with assert_raises(TypeError): 17 | hash({}) 18 | 19 | with assert_raises(TypeError): 20 | hash(set()) 21 | 22 | with assert_raises(TypeError): 23 | hash([]) 24 | -------------------------------------------------------------------------------- /Lib/test/recursion.tar: -------------------------------------------------------------------------------- 1 | bcaller00010002755 g00000 X= -------------------------------------------------------------------------------- /Lib/venv/scripts/nt/deactivate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if defined _OLD_VIRTUAL_PROMPT ( 4 | set "PROMPT=%_OLD_VIRTUAL_PROMPT%" 5 | ) 6 | set _OLD_VIRTUAL_PROMPT= 7 | 8 | if defined _OLD_VIRTUAL_PYTHONHOME ( 9 | set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%" 10 | set _OLD_VIRTUAL_PYTHONHOME= 11 | ) 12 | 13 | if defined _OLD_VIRTUAL_PATH ( 14 | set "PATH=%_OLD_VIRTUAL_PATH%" 15 | ) 16 | 17 | set _OLD_VIRTUAL_PATH= 18 | 19 | set VIRTUAL_ENV= 20 | set VIRTUAL_ENV_PROMPT= 21 | 22 | :END 23 | -------------------------------------------------------------------------------- /compiler/ast/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython-ast" 3 | version = "0.2.0" 4 | description = "AST definitions for RustPython" 5 | authors = ["RustPython Team"] 6 | edition = "2021" 7 | repository = "https://github.com/RustPython/RustPython" 8 | license = "MIT" 9 | 10 | [features] 11 | default = ["constant-optimization", "fold"] 12 | constant-optimization = ["fold"] 13 | fold = [] 14 | 15 | [dependencies] 16 | ruff_text_size = { path = "../../ruff_text_size" } 17 | 18 | num-bigint = { workspace = true } 19 | -------------------------------------------------------------------------------- /derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython-derive" 3 | version = "0.2.0" 4 | description = "Rust language extensions and macros specific to rustpython." 5 | authors = ["RustPython Team"] 6 | repository = "https://github.com/RustPython/RustPython" 7 | license = "MIT" 8 | edition = "2021" 9 | 10 | [lib] 11 | proc-macro = true 12 | 13 | [dependencies] 14 | rustpython-compiler = { path = "../compiler", version = "0.2.0" } 15 | rustpython-derive-impl = { path = "../derive-impl" } 16 | syn = { workspace = true } 17 | -------------------------------------------------------------------------------- /Lib/test/test_sqlite3/__init__.py: -------------------------------------------------------------------------------- 1 | from test.support import import_helper, load_package_tests, verbose 2 | 3 | # Skip test if _sqlite3 module not installed. 4 | import_helper.import_module('_sqlite3') 5 | 6 | import os 7 | import sqlite3 8 | 9 | # Implement the unittest "load tests" protocol. 10 | def load_tests(*args): 11 | pkg_dir = os.path.dirname(__file__) 12 | return load_package_tests(pkg_dir, *args) 13 | 14 | if verbose: 15 | print(f"test_sqlite3: testing with SQLite version {sqlite3.sqlite_version}") 16 | -------------------------------------------------------------------------------- /Lib/test/tokenize_tests-utf8-coding-cookie-and-no-utf8-bom-sig.txt: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # IMPORTANT: unlike the other test_tokenize-*.txt files, this file 3 | # does NOT have the utf-8 BOM signature '\xef\xbb\xbf' at the start 4 | # of it. Make sure this is not added inadvertently by your editor 5 | # if any changes are made to this file! 6 | 7 | # Arbitrary encoded utf-8 text (stolen from test_doctest2.py). 8 | x = 'ЉЊЈЁЂ' 9 | def y(): 10 | """ 11 | And again in a comment. ЉЊЈЁЂ 12 | """ 13 | pass 14 | -------------------------------------------------------------------------------- /Lib/ctypes/test/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | from test import support 4 | from test.support import import_helper 5 | 6 | 7 | # skip tests if _ctypes was not built 8 | ctypes = import_helper.import_module('ctypes') 9 | ctypes_symbols = dir(ctypes) 10 | 11 | def need_symbol(name): 12 | return unittest.skipUnless(name in ctypes_symbols, 13 | '{!r} is required'.format(name)) 14 | 15 | def load_tests(*args): 16 | return support.load_package_tests(os.path.dirname(__file__), *args) 17 | -------------------------------------------------------------------------------- /.theia/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | "version": "0.2.0", 5 | "configurations": [ 6 | { 7 | "type": "lldb", 8 | "request": "launch", 9 | "name": "Debug Rust Code", 10 | //"preLaunchTask": "cargo", 11 | "program": "${workspaceFolder}/target/debug/rustpython", 12 | "cwd": "${workspaceFolder}", 13 | //"valuesFormatting": "parseText" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /Lib/test/ann_module3.py: -------------------------------------------------------------------------------- 1 | """ 2 | Correct syntax for variable annotation that should fail at runtime 3 | in a certain manner. More examples are in test_grammar and test_parser. 4 | """ 5 | 6 | def f_bad_ann(): 7 | __annotations__[1] = 2 8 | 9 | class C_OK: 10 | def __init__(self, x: int) -> None: 11 | self.x: no_such_name = x # This one is OK as proposed by Guido 12 | 13 | class D_bad_ann: 14 | def __init__(self, x: int) -> None: 15 | sfel.y: int = 0 16 | 17 | def g_bad_ann(): 18 | no_such_name.attr: int = 0 19 | -------------------------------------------------------------------------------- /Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt: -------------------------------------------------------------------------------- 1 | # -*- coding: latin1 -*- 2 | # IMPORTANT: this file has the utf-8 BOM signature '\xef\xbb\xbf' 3 | # at the start of it. Make sure this is preserved if any changes 4 | # are made! Also note that the coding cookie above conflicts with 5 | # the presence of a utf-8 BOM signature -- this is intended. 6 | 7 | # Arbitrary encoded utf-8 text (stolen from test_doctest2.py). 8 | x = 'ЉЊЈЁЂ' 9 | def y(): 10 | """ 11 | And again in a comment. ЉЊЈЁЂ 12 | """ 13 | pass 14 | -------------------------------------------------------------------------------- /extra_tests/snippets/jit.py: -------------------------------------------------------------------------------- 1 | 2 | def foo(): 3 | a = 5 4 | return 10 + a 5 | 6 | 7 | def bar(): 8 | a = 1e6 9 | return a / 5.0 10 | 11 | 12 | def baz(a: int, b: int): 13 | return a + b + 12 14 | 15 | 16 | def tests(): 17 | assert foo() == 15 18 | assert bar() == 2e5 19 | assert baz(17, 20) == 49 20 | assert baz(17, 22.5) == 51.5 21 | 22 | 23 | tests() 24 | 25 | if hasattr(foo, "__jit__"): 26 | print("Has jit") 27 | foo.__jit__() 28 | bar.__jit__() 29 | baz.__jit__() 30 | tests() 31 | -------------------------------------------------------------------------------- /scripts/install-openssl.ps1: -------------------------------------------------------------------------------- 1 | # From the Actix Web windows workflow: 2 | # https://github.com/actix/actix-web/blob/master/.github/workflows/windows.yml 3 | vcpkg integrate install 4 | vcpkg install openssl:x64-windows 5 | Copy-Item C:\vcpkg\installed\x64-windows\bin\libcrypto-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libcrypto.dll 6 | Copy-Item C:\vcpkg\installed\x64-windows\bin\libssl-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libssl.dll 7 | Get-ChildItem C:\vcpkg\installed\x64-windows\bin 8 | Get-ChildItem C:\vcpkg\installed\x64-windows\lib 9 | -------------------------------------------------------------------------------- /Lib/test/test_json/test_pass2.py: -------------------------------------------------------------------------------- 1 | from test.test_json import PyTest, CTest 2 | 3 | 4 | # from http://json.org/JSON_checker/test/pass2.json 5 | JSON = r''' 6 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] 7 | ''' 8 | 9 | class TestPass2: 10 | def test_parse(self): 11 | # test in/out equivalence and parsing 12 | res = self.loads(JSON) 13 | out = self.dumps(res) 14 | self.assertEqual(res, self.loads(out)) 15 | 16 | 17 | class TestPyPass2(TestPass2, PyTest): pass 18 | class TestCPass2(TestPass2, CTest): pass 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/report-incompatibility.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Report incompatibility 3 | about: Report an incompatibility between RustPython and CPython 4 | title: '' 5 | labels: feat 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Feature 11 | 12 | 13 | 14 | ## Python Documentation 15 | 16 | 17 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_none.py: -------------------------------------------------------------------------------- 1 | assert None is None 2 | 3 | y = None 4 | x = None 5 | assert x is y 6 | 7 | def none(): 8 | pass 9 | 10 | def none2(): 11 | return None 12 | 13 | assert none() is none() 14 | assert none() is x 15 | 16 | assert none() is none2() 17 | 18 | assert str(None) == 'None' 19 | assert repr(None) == 'None' 20 | assert type(None)() is None 21 | 22 | assert None.__eq__(3) is NotImplemented 23 | assert None.__ne__(3) is NotImplemented 24 | assert None.__eq__(None) is True 25 | assert None.__ne__(None) is False 26 | 27 | -------------------------------------------------------------------------------- /stdlib/src/sha256.rs: -------------------------------------------------------------------------------- 1 | pub(crate) use _sha256::make_module; 2 | 3 | #[pymodule] 4 | mod _sha256 { 5 | use crate::hashlib::_hashlib::{local_sha224, local_sha256, HashArgs}; 6 | use crate::vm::{PyPayload, PyResult, VirtualMachine}; 7 | 8 | #[pyfunction] 9 | fn sha224(args: HashArgs, vm: &VirtualMachine) -> PyResult { 10 | Ok(local_sha224(args).into_pyobject(vm)) 11 | } 12 | 13 | #[pyfunction] 14 | fn sha256(args: HashArgs, vm: &VirtualMachine) -> PyResult { 15 | Ok(local_sha256(args).into_pyobject(vm)) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Lib/unittest/__main__.py: -------------------------------------------------------------------------------- 1 | """Main entry point""" 2 | 3 | import sys 4 | if sys.argv[0].endswith("__main__.py"): 5 | import os.path 6 | # We change sys.argv[0] to make help message more useful 7 | # use executable without path, unquoted 8 | # (it's just a hint anyway) 9 | # (if you have spaces in your executable you get what you deserve!) 10 | executable = os.path.basename(sys.executable) 11 | sys.argv[0] = executable + " -m unittest" 12 | del os 13 | 14 | __unittest = True 15 | 16 | from .main import main 17 | 18 | main(module=None) 19 | -------------------------------------------------------------------------------- /Lib/dis.py: -------------------------------------------------------------------------------- 1 | from _dis import * 2 | 3 | 4 | # Disassembling a file by following cpython Lib/dis.py 5 | def _test(): 6 | """Simple test program to disassemble a file.""" 7 | import argparse 8 | 9 | parser = argparse.ArgumentParser() 10 | parser.add_argument('infile', type=argparse.FileType('rb'), nargs='?', default='-') 11 | args = parser.parse_args() 12 | with args.infile as infile: 13 | source = infile.read() 14 | code = compile(source, args.infile.name, "exec") 15 | dis(code) 16 | 17 | if __name__ == "__main__": 18 | _test() 19 | -------------------------------------------------------------------------------- /ruff_text_size/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ruff_text_size" 3 | version = "0.0.0" 4 | publish = false 5 | edition = "2021" 6 | rust-version = "1.67.1" 7 | 8 | [dependencies] 9 | serde = { version="1.0.152", optional = true, default_features = false } 10 | schemars = { version = "0.8.12", optional = true } 11 | 12 | [dev-dependencies] 13 | serde_test = { version = "1.0.152" } 14 | static_assertions = { version = "1.1.0" } 15 | 16 | [features] 17 | serde = ["dep:serde"] 18 | 19 | [[test]] 20 | name = "serde" 21 | path = "tests/serde.rs" 22 | required-features = ["serde"] -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/out_inC14N3_c14nPrefix.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /compiler/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ors.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/codegen/src/compile.rs 3 | expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")" 4 | --- 5 | 1 0 LoadConst (True) 6 | 1 JumpIfTrue (6) 7 | 2 LoadConst (False) 8 | 3 JumpIfTrue (6) 9 | 4 LoadConst (False) 10 | 5 JumpIfFalse (6) 11 | 12 | 2 >> 6 LoadConst (None) 13 | 7 ReturnValue 14 | 15 | -------------------------------------------------------------------------------- /compiler/codegen/src/snapshots/rustpython_compiler_core__compile__tests__if_ors.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/src/compile.rs 3 | expression: "compile_exec(\"\\\nif True or False or False:\n pass\n\")" 4 | --- 5 | 1 0 LoadConst (True) 6 | 1 JumpIfTrue (6) 7 | 2 LoadConst (False) 8 | 3 JumpIfTrue (6) 9 | 4 LoadConst (False) 10 | 5 JumpIfFalse (6) 11 | 12 | 2 >> 6 LoadConst (None) 13 | 7 ReturnValue 14 | 15 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_print.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | import io 3 | 4 | print(2 + 3) 5 | 6 | assert_raises(TypeError, print, 'test', end=4, _msg='wrong type passed to end') 7 | assert_raises(TypeError, print, 'test', sep=['a'], _msg='wrong type passed to sep') 8 | 9 | try: 10 | print('test', end=None, sep=None, flush=None) 11 | except: 12 | assert False, 'Expected None passed to end, sep, and flush to not raise errors' 13 | 14 | buf = io.StringIO() 15 | print('hello, world', file=buf) 16 | assert buf.getvalue() == 'hello, world\n', buf.getvalue() 17 | -------------------------------------------------------------------------------- /Lib/antigravity.py: -------------------------------------------------------------------------------- 1 | 2 | import webbrowser 3 | import hashlib 4 | 5 | webbrowser.open("https://xkcd.com/353/") 6 | 7 | def geohash(latitude, longitude, datedow): 8 | '''Compute geohash() using the Munroe algorithm. 9 | 10 | >>> geohash(37.421542, -122.085589, b'2005-05-26-10458.68') 11 | 37.857713 -122.544543 12 | 13 | ''' 14 | # https://xkcd.com/426/ 15 | h = hashlib.md5(datedow, usedforsecurity=False).hexdigest() 16 | p, q = [('%f' % float.fromhex('0.' + x)) for x in (h[:16], h[16:32])] 17 | print('%d%s %d%s' % (latitude, p[1:], longitude, q[1:])) 18 | -------------------------------------------------------------------------------- /compiler/codegen/src/snapshots/rustpython_codegen__compile__tests__if_ands.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/codegen/src/compile.rs 3 | expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")" 4 | --- 5 | 1 0 LoadConst (True) 6 | 1 JumpIfFalse (6) 7 | 2 LoadConst (False) 8 | 3 JumpIfFalse (6) 9 | 4 LoadConst (False) 10 | 5 JumpIfFalse (6) 11 | 12 | 2 >> 6 LoadConst (None) 13 | 7 ReturnValue 14 | 15 | -------------------------------------------------------------------------------- /compiler/codegen/src/snapshots/rustpython_compiler_core__compile__tests__if_ands.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/src/compile.rs 3 | expression: "compile_exec(\"\\\nif True and False and False:\n pass\n\")" 4 | --- 5 | 1 0 LoadConst (True) 6 | 1 JumpIfFalse (6) 7 | 2 LoadConst (False) 8 | 3 JumpIfFalse (6) 9 | 4 LoadConst (False) 10 | 5 JumpIfFalse (6) 11 | 12 | 2 >> 6 LoadConst (None) 13 | 7 ReturnValue 14 | 15 | -------------------------------------------------------------------------------- /extra_tests/snippets/operator_cast.py: -------------------------------------------------------------------------------- 1 | x = 1 2 | y = 1.1 3 | assert x+y == 2.1 4 | #print(x+y) 5 | 6 | x = 1.1 7 | y = 1 8 | assert x+y == 2.1 9 | #print(x+y) 10 | 11 | x = 1.1 12 | y = 2.1 13 | assert x+y == 3.2 14 | #print(x+y) 15 | 16 | x = "ab" 17 | y = "cd" 18 | assert x+y == "abcd" 19 | #print(x+y) 20 | 21 | x = 2 22 | y = 3 23 | assert x**y == 8 24 | #print(x**y) 25 | 26 | x = 2.0 27 | y = 3 28 | assert x**y == 8.0 29 | #print(x**y) 30 | 31 | x = 2 32 | y = 3.0 33 | assert x**y == 8.0 34 | #print(x**y) 35 | 36 | x = 2.0 37 | y = 3.0 38 | assert x**y == 8.0 39 | #print(x**y) 40 | -------------------------------------------------------------------------------- /ruff_text_size/tests/constructors.rs: -------------------------------------------------------------------------------- 1 | use ruff_text_size::TextSize; 2 | 3 | #[derive(Copy, Clone)] 4 | struct BadRope<'a>(&'a [&'a str]); 5 | 6 | impl BadRope<'_> { 7 | fn text_len(self) -> TextSize { 8 | self.0.iter().copied().map(TextSize::of).sum() 9 | } 10 | } 11 | 12 | #[test] 13 | fn main() { 14 | let x: char = 'c'; 15 | let _ = TextSize::of(x); 16 | 17 | let x: &str = "hello"; 18 | let _ = TextSize::of(x); 19 | 20 | let x: &String = &"hello".into(); 21 | let _ = TextSize::of(x); 22 | 23 | let _ = BadRope(&[""]).text_len(); 24 | } 25 | -------------------------------------------------------------------------------- /compiler/codegen/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Compile a Python AST or source code into bytecode consumable by RustPython. 2 | #![doc(html_logo_url = "https://raw.githubusercontent.com/RustPython/RustPython/main/logo.png")] 3 | #![doc(html_root_url = "https://docs.rs/rustpython-compiler/")] 4 | 5 | #[macro_use] 6 | extern crate log; 7 | 8 | type IndexMap = indexmap::IndexMap; 9 | type IndexSet = indexmap::IndexSet; 10 | 11 | pub mod compile; 12 | pub mod error; 13 | pub mod ir; 14 | pub mod symboltable; 15 | 16 | pub use compile::CompileOpts; 17 | -------------------------------------------------------------------------------- /derive-impl/src/pypayload.rs: -------------------------------------------------------------------------------- 1 | use proc_macro2::TokenStream; 2 | use quote::quote; 3 | use syn::{DeriveInput, Result}; 4 | 5 | pub(crate) fn impl_pypayload(input: DeriveInput) -> Result { 6 | let ty = &input.ident; 7 | 8 | let ret = quote! { 9 | impl ::rustpython_vm::PyPayload for #ty { 10 | fn class(_ctx: &::rustpython_vm::vm::Context) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> { 11 | ::static_type() 12 | } 13 | } 14 | }; 15 | Ok(ret) 16 | } 17 | -------------------------------------------------------------------------------- /examples/call_between_rust_and_python.py: -------------------------------------------------------------------------------- 1 | from rust_py_module import RustStruct, rust_function 2 | 3 | class PythonPerson: 4 | def __init__(self, name): 5 | self.name = name 6 | 7 | def python_callback(): 8 | python_person = PythonPerson("Peter Python") 9 | rust_object = rust_function(42, "This is a python string", python_person) 10 | print("Printing member 'numbers' from rust struct: ", rust_object.numbers) 11 | rust_object.print_in_rust_from_python() 12 | 13 | def take_string(string): 14 | print("Calling python function from rust with string: " + string) 15 | -------------------------------------------------------------------------------- /examples/hello_embed.rs: -------------------------------------------------------------------------------- 1 | use rustpython_vm as vm; 2 | 3 | fn main() -> vm::PyResult<()> { 4 | vm::Interpreter::without_stdlib(Default::default()).enter(|vm| { 5 | let scope = vm.new_scope_with_builtins(); 6 | 7 | let code_obj = vm 8 | .compile( 9 | r#"print("Hello World!")"#, 10 | vm::compiler::Mode::Exec, 11 | "".to_owned(), 12 | ) 13 | .map_err(|err| vm.new_syntax_error(&err))?; 14 | 15 | vm.run_code_obj(code_obj, scope)?; 16 | 17 | Ok(()) 18 | }) 19 | } 20 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_sys_getframe.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | value = 189 4 | locals_dict = sys._getframe().f_locals 5 | assert locals_dict['value'] == 189 6 | foo = 'bar' 7 | assert locals_dict['foo'] == foo 8 | 9 | def test_function(): 10 | x = 17 11 | assert sys._getframe().f_locals is not locals_dict 12 | assert sys._getframe().f_locals['x'] == 17 13 | assert sys._getframe(1).f_locals['foo'] == 'bar' 14 | 15 | test_function() 16 | 17 | class TestClass(): 18 | def __init__(self): 19 | assert sys._getframe().f_locals['self'] == self 20 | 21 | TestClass() 22 | -------------------------------------------------------------------------------- /vm/src/protocol/mod.rs: -------------------------------------------------------------------------------- 1 | mod buffer; 2 | mod callable; 3 | mod iter; 4 | mod mapping; 5 | mod number; 6 | mod object; 7 | mod sequence; 8 | 9 | pub use buffer::{BufferDescriptor, BufferMethods, BufferResizeGuard, PyBuffer, VecBuffer}; 10 | pub use callable::PyCallable; 11 | pub use iter::{PyIter, PyIterIter, PyIterReturn}; 12 | pub use mapping::{PyMapping, PyMappingMethods}; 13 | pub use number::{ 14 | PyNumber, PyNumberBinaryFunc, PyNumberBinaryOp, PyNumberMethods, PyNumberSlots, 15 | PyNumberTernaryOp, PyNumberUnaryFunc, 16 | }; 17 | pub use sequence::{PySequence, PySequenceMethods}; 18 | -------------------------------------------------------------------------------- /Lib/test/_typed_dict_helper.py: -------------------------------------------------------------------------------- 1 | """Used to test `get_type_hints()` on a cross-module inherited `TypedDict` class 2 | 3 | This script uses future annotations to postpone a type that won't be available 4 | on the module inheriting from to `Foo`. The subclass in the other module should 5 | look something like this: 6 | 7 | class Bar(_typed_dict_helper.Foo, total=False): 8 | b: int 9 | """ 10 | 11 | from __future__ import annotations 12 | 13 | from typing import Optional, TypedDict 14 | 15 | OptionalIntType = Optional[int] 16 | 17 | class Foo(TypedDict): 18 | a: OptionalIntType 19 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_fstring_yield_expr.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..10, 8 | custom: (), 9 | node: FormattedValue { 10 | value: Located { 11 | range: 3..8, 12 | custom: (), 13 | node: Yield { 14 | value: None, 15 | }, 16 | }, 17 | conversion: 0, 18 | format_spec: None, 19 | }, 20 | }, 21 | ] 22 | -------------------------------------------------------------------------------- /jit/tests/none_tests.rs: -------------------------------------------------------------------------------- 1 | #[test] 2 | fn test_not() { 3 | let not_ = jit_function! { not_(x: i64) -> bool => r##" 4 | def not_(x: int): 5 | return not None 6 | "## }; 7 | 8 | assert_eq!(not_(0), Ok(true)); 9 | } 10 | 11 | #[test] 12 | fn test_if_not() { 13 | let if_not = jit_function! { if_not(x: i64) -> i64 => r##" 14 | def if_not(x: int): 15 | if not None: 16 | return 1 17 | else: 18 | return 0 19 | 20 | return -1 21 | "## }; 22 | 23 | assert_eq!(if_not(0), Ok(1)); 24 | } 25 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inC14N4.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | ]> 5 | 6 | First line Second line 7 | 2 8 | "0" && value<"10" ?"valid":"error"]]> 9 | valid 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /extra_tests/snippets/intro/3.1.1.2.py: -------------------------------------------------------------------------------- 1 | assert 5.666666666666667 == 17 / 3 # classic division returns a float 2 | 3 | assert 5 == 17 // 3 # floor division discards the fractional part 4 | 5 | assert 2 == 17 % 3 # the % operator returns the remainder of the division 6 | 7 | assert 17 == 5 * 3 + 2 # result * divisor + remainder 8 | 9 | print(17 / 3) # classic division returns a float 10 | 11 | print(17 // 3) # floor division discards the fractional part 12 | 13 | print(17 % 3) # the % operator returns the remainder of the division 14 | 15 | print(5 * 3 + 2) # result * divisor + remainder 16 | -------------------------------------------------------------------------------- /Lib/test/xmltests.py: -------------------------------------------------------------------------------- 1 | # Convenience test module to run all of the XML-related tests in the 2 | # standard library. 3 | 4 | import sys 5 | import test.support 6 | 7 | test.support.verbose = 0 8 | 9 | def runtest(name): 10 | __import__(name) 11 | module = sys.modules[name] 12 | if hasattr(module, "test_main"): 13 | module.test_main() 14 | 15 | runtest("test.test_minidom") 16 | runtest("test.test_pyexpat") 17 | runtest("test.test_sax") 18 | runtest("test.test_xml_dom_minicompat") 19 | runtest("test.test_xml_etree") 20 | runtest("test.test_xml_etree_c") 21 | runtest("test.test_xmlrpc") 22 | -------------------------------------------------------------------------------- /benches/benchmarks/mandelbrot.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # coding: utf-8 3 | 4 | w = 50.0 5 | h = 50.0 6 | 7 | y = 0.0 8 | while y < h: 9 | x = 0.0 10 | while x < w: 11 | Zr, Zi, Tr, Ti = 0.0, 0.0, 0.0, 0.0 12 | Cr = 2*x/w - 1.5 13 | Ci = 2*y/h - 1.0 14 | 15 | i = 0 16 | while i < 50 and Tr+Ti <= 4: 17 | Zi = 2*Zr*Zi + Ci 18 | Zr = Tr - Ti + Cr 19 | Tr = Zr * Zr 20 | Ti = Zi * Zi 21 | i = i+1 22 | 23 | if Tr+Ti <= 4: 24 | # print('*', end='') 25 | pass 26 | else: 27 | # print('·', end='') 28 | pass 29 | 30 | x = x+1 31 | 32 | # print() 33 | y = y+1 34 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__context__tests__del_name.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/context.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..5, 8 | custom: (), 9 | node: Delete { 10 | targets: [ 11 | Located { 12 | range: 4..5, 13 | custom: (), 14 | node: Name { 15 | id: "x", 16 | ctx: Del, 17 | }, 18 | }, 19 | ], 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__bell_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..9, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..9, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{7}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__hts_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..9, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..9, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{88}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /common/src/char.rs: -------------------------------------------------------------------------------- 1 | use unic_ucd_category::GeneralCategory; 2 | 3 | /// According to python following categories aren't printable: 4 | /// * Cc (Other, Control) 5 | /// * Cf (Other, Format) 6 | /// * Cs (Other, Surrogate) 7 | /// * Co (Other, Private Use) 8 | /// * Cn (Other, Not Assigned) 9 | /// * Zl Separator, Line ('\u2028', LINE SEPARATOR) 10 | /// * Zp Separator, Paragraph ('\u2029', PARAGRAPH SEPARATOR) 11 | /// * Zs (Separator, Space) other than ASCII space('\x20'). 12 | pub fn is_printable(c: char) -> bool { 13 | let cat = GeneralCategory::of(c); 14 | !(cat.is_other() || cat.is_separator()) 15 | } 16 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__backspace_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..15, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..15, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{8}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__delete_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..12, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..12, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{7f}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__escape_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..12, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..12, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{1b}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__form_feed_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..15, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..15, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{c}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_decorator.py: -------------------------------------------------------------------------------- 1 | 2 | def logged(f): 3 | def wrapper(a, b): 4 | print('Calling function', f) 5 | return f(a, b + 1) 6 | return wrapper 7 | 8 | 9 | @logged 10 | def add(a, b): 11 | return a + b 12 | 13 | c = add(10, 3) 14 | 15 | assert c == 14 16 | 17 | 18 | @logged 19 | def add3(a, b, c=2): 20 | return a + b + c 21 | 22 | 23 | d = add3(12, 5) 24 | 25 | assert d == 20 26 | 27 | 28 | def f(func): return lambda: 42 29 | class A: pass 30 | a = A() 31 | a.a = A() 32 | a.a.x = f 33 | 34 | @a.a.x 35 | def func(): 36 | pass 37 | 38 | assert func() == 42 39 | -------------------------------------------------------------------------------- /Lib/test/test_future5.py: -------------------------------------------------------------------------------- 1 | # Check that multiple features can be enabled. 2 | from __future__ import unicode_literals, print_function 3 | 4 | import sys 5 | import unittest 6 | from test import support 7 | 8 | 9 | class TestMultipleFeatures(unittest.TestCase): 10 | 11 | def test_unicode_literals(self): 12 | self.assertIsInstance("", str) 13 | 14 | def test_print_function(self): 15 | with support.captured_output("stderr") as s: 16 | print("foo", file=sys.stderr) 17 | self.assertEqual(s.getvalue(), "foo\n") 18 | 19 | 20 | if __name__ == '__main__': 21 | unittest.main() 22 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_string.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/parser.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..13, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..13, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "Hello world", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__carriage_return_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..21, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..21, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\r", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_mappingproxy.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | class A(dict): 4 | def a(): 5 | pass 6 | 7 | def b(): 8 | pass 9 | 10 | 11 | assert A.__dict__['a'] == A.a 12 | with assert_raises(KeyError) as cm: 13 | A.__dict__['not here'] 14 | 15 | assert cm.exception.args[0] == "not here" 16 | 17 | assert 'b' in A.__dict__ 18 | assert 'c' not in A.__dict__ 19 | 20 | assert '__dict__' in A.__dict__ 21 | 22 | assert A.__dict__.get("not here", "default") == "default" 23 | assert A.__dict__.get("a", "default") is A.a 24 | assert A.__dict__.get("not here") is None 25 | -------------------------------------------------------------------------------- /wasm/tests/test_demo.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | RUN_CODE_TEMPLATE = """ 4 | var output = ""; 5 | save_output = function(text) {{ 6 | output += text 7 | }}; 8 | var vm = window.rp.vmStore.init('test_vm'); 9 | vm.setStdout(save_output); 10 | vm.exec('{}'); 11 | vm.destroy(); 12 | return output; 13 | """ 14 | 15 | 16 | @pytest.mark.parametrize( 17 | "script, output", [("print(5)", "5"), ("a=5;b=4;print(a+b)", "9")] 18 | ) 19 | def test_demo(wdriver, script, output): 20 | script = RUN_CODE_TEMPLATE.format(script) 21 | script_output = wdriver.execute_script(script) 22 | assert script_output.strip() == output 23 | -------------------------------------------------------------------------------- /Lib/test/test_future3.py: -------------------------------------------------------------------------------- 1 | from __future__ import nested_scopes 2 | from __future__ import division 3 | 4 | import unittest 5 | 6 | x = 2 7 | def nester(): 8 | x = 3 9 | def inner(): 10 | return x 11 | return inner() 12 | 13 | 14 | class TestFuture(unittest.TestCase): 15 | 16 | def test_floor_div_operator(self): 17 | self.assertEqual(7 // 2, 3) 18 | 19 | def test_true_div_as_default(self): 20 | self.assertAlmostEqual(7 / 2, 3.5) 21 | 22 | def test_nested_scopes(self): 23 | self.assertEqual(nester(), 3) 24 | 25 | if __name__ == "__main__": 26 | unittest.main() 27 | -------------------------------------------------------------------------------- /Lib/test/test_importlib/partial/pool_in_threads.py: -------------------------------------------------------------------------------- 1 | import multiprocessing 2 | import os 3 | import threading 4 | import traceback 5 | 6 | 7 | def t(): 8 | try: 9 | with multiprocessing.Pool(1): 10 | pass 11 | except Exception: 12 | traceback.print_exc() 13 | os._exit(1) 14 | 15 | 16 | def main(): 17 | threads = [] 18 | for i in range(20): 19 | threads.append(threading.Thread(target=t)) 20 | for thread in threads: 21 | thread.start() 22 | for thread in threads: 23 | thread.join() 24 | 25 | 26 | if __name__ == "__main__": 27 | main() 28 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_concat.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..16, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..16, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "Hello world", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_1.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..17, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..17, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "Hello world", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /Lib/asyncio/compat.py: -------------------------------------------------------------------------------- 1 | """Compatibility helpers for the different Python versions.""" 2 | 3 | import sys 4 | 5 | PY34 = sys.version_info >= (3, 4) 6 | PY35 = sys.version_info >= (3, 5) 7 | PY352 = sys.version_info >= (3, 5, 2) 8 | 9 | 10 | def flatten_list_bytes(list_of_data): 11 | """Concatenate a sequence of bytes-like objects.""" 12 | if not PY34: 13 | # On Python 3.3 and older, bytes.join() doesn't handle 14 | # memoryview. 15 | list_of_data = ( 16 | bytes(data) if isinstance(data, memoryview) else data 17 | for data in list_of_data) 18 | return b''.join(list_of_data) 19 | -------------------------------------------------------------------------------- /ruff_text_size/tests/auto_traits.rs: -------------------------------------------------------------------------------- 1 | use { 2 | ruff_text_size::{TextRange, TextSize}, 3 | static_assertions::assert_impl_all, 4 | std::{ 5 | fmt::Debug, 6 | hash::Hash, 7 | marker::{Send, Sync}, 8 | panic::{RefUnwindSafe, UnwindSafe}, 9 | }, 10 | }; 11 | 12 | // auto traits 13 | assert_impl_all!(TextSize: Send, Sync, Unpin, UnwindSafe, RefUnwindSafe); 14 | assert_impl_all!(TextRange: Send, Sync, Unpin, UnwindSafe, RefUnwindSafe); 15 | 16 | // common traits 17 | assert_impl_all!(TextSize: Copy, Debug, Default, Hash, Ord); 18 | assert_impl_all!(TextRange: Copy, Debug, Default, Hash, Eq); 19 | -------------------------------------------------------------------------------- /stdlib/src/blake2.rs: -------------------------------------------------------------------------------- 1 | // spell-checker:ignore usedforsecurity HASHXOF 2 | 3 | pub(crate) use _blake2::make_module; 4 | 5 | #[pymodule] 6 | mod _blake2 { 7 | use crate::hashlib::_hashlib::{local_blake2b, local_blake2s, BlakeHashArgs}; 8 | use crate::vm::{PyPayload, PyResult, VirtualMachine}; 9 | 10 | #[pyfunction] 11 | fn blake2b(args: BlakeHashArgs, vm: &VirtualMachine) -> PyResult { 12 | Ok(local_blake2b(args).into_pyobject(vm)) 13 | } 14 | 15 | #[pyfunction] 16 | fn blake2s(args: BlakeHashArgs, vm: &VirtualMachine) -> PyResult { 17 | Ok(local_blake2s(args).into_pyobject(vm)) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Lib/README.md: -------------------------------------------------------------------------------- 1 | # Standard Library for RustPython 2 | 3 | This directory contains all of the Python files that make up the standard 4 | library for RustPython. 5 | 6 | Most of these files are copied over from the CPython repository (the 3.7 7 | branch), with slight modifications to allow them to work under RustPython. The 8 | current goal is to complete the standard library with as few modifications as 9 | possible. Current modifications are just temporary workarounds for bugs/missing 10 | feature within the RustPython implementation. 11 | 12 | The first big module we are targeting is `unittest`, so we can leverage the 13 | CPython test suite. 14 | -------------------------------------------------------------------------------- /compiler/core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython-compiler-core" 3 | description = "RustPython specific bytecode." 4 | version = "0.2.0" 5 | authors = ["RustPython Team"] 6 | edition = "2021" 7 | repository = "https://github.com/RustPython/RustPython" 8 | license = "MIT" 9 | 10 | [dependencies] 11 | bitflags = { workspace = true } 12 | itertools = { workspace = true } 13 | num-bigint = { workspace = true } 14 | num-complex = { workspace = true } 15 | serde = { version = "1.0.133", optional = true, default-features = false, features = ["derive"] } 16 | ruff_text_size = { path = "../../ruff_text_size" } 17 | 18 | lz4_flex = "0.9.2" 19 | 20 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__character_tabulation_with_justification_alias.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..45, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..45, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "\u{89}", 16 | ), 17 | kind: None, 18 | }, 19 | }, 20 | }, 21 | }, 22 | ] 23 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_str_encode.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | try: 4 | b" \xff".decode("ascii") 5 | except UnicodeDecodeError as e: 6 | assert e.start == 3 7 | assert e.end == 4 8 | else: 9 | assert False, "should have thrown UnicodeDecodeError" 10 | 11 | assert_raises(UnicodeEncodeError, "¿como estás?".encode, "ascii") 12 | 13 | def round_trip(s, encoding="utf-8"): 14 | encoded = s.encode(encoding) 15 | decoded = encoded.decode(encoding) 16 | assert s == decoded 17 | 18 | round_trip("👺♦ 𝐚Şđƒ ☆☝") 19 | round_trip("☢🐣 ᖇ𝓤𝕊тⓟ𝕐𝕥卄σ𝔫 ♬👣") 20 | round_trip("💀👌 ק𝔂tℍⓞ𝓷 3 🔥👤") 21 | -------------------------------------------------------------------------------- /Lib/ctypes/test/test_delattr.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from ctypes import * 3 | 4 | class X(Structure): 5 | _fields_ = [("foo", c_int)] 6 | 7 | class TestCase(unittest.TestCase): 8 | def test_simple(self): 9 | self.assertRaises(TypeError, 10 | delattr, c_int(42), "value") 11 | 12 | def test_chararray(self): 13 | self.assertRaises(TypeError, 14 | delattr, (c_char * 5)(), "value") 15 | 16 | def test_struct(self): 17 | self.assertRaises(TypeError, 18 | delattr, X(), "foo") 19 | 20 | if __name__ == "__main__": 21 | unittest.main() 22 | -------------------------------------------------------------------------------- /Lib/unittest/test/testmock/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import unittest 4 | 5 | 6 | here = os.path.dirname(__file__) 7 | loader = unittest.defaultTestLoader 8 | 9 | def load_tests(*args): 10 | suite = unittest.TestSuite() 11 | # TODO: RUSTPYTHON; allow objects to be mocked better 12 | return suite 13 | for fn in os.listdir(here): 14 | if fn.startswith("test") and fn.endswith(".py"): 15 | modname = "unittest.test.testmock." + fn[:-3] 16 | __import__(modname) 17 | module = sys.modules[modname] 18 | suite.addTest(loader.loadTestsFromModule(module)) 19 | return suite 20 | -------------------------------------------------------------------------------- /Lib/xml/__init__.py: -------------------------------------------------------------------------------- 1 | """Core XML support for Python. 2 | 3 | This package contains four sub-packages: 4 | 5 | dom -- The W3C Document Object Model. This supports DOM Level 1 + 6 | Namespaces. 7 | 8 | parsers -- Python wrappers for XML parsers (currently only supports Expat). 9 | 10 | sax -- The Simple API for XML, developed by XML-Dev, led by David 11 | Megginson and ported to Python by Lars Marius Garshol. This 12 | supports the SAX 2 API. 13 | 14 | etree -- The ElementTree XML library. This is a subset of the full 15 | ElementTree XML release. 16 | 17 | """ 18 | 19 | 20 | __all__ = ["dom", "parsers", "sax", "etree"] 21 | -------------------------------------------------------------------------------- /extra_tests/snippets/index_overflow.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def expect_cannot_fit_index_error(s, index): 5 | try: 6 | s[index] 7 | except IndexError as error: 8 | assert str(error) == "cannot fit 'int' into an index-sized integer" 9 | else: 10 | assert False 11 | 12 | 13 | MAX_INDEX = sys.maxsize + 1 14 | MIN_INDEX = -(MAX_INDEX + 1) 15 | 16 | test_str = "test" 17 | expect_cannot_fit_index_error(test_str, MIN_INDEX) 18 | expect_cannot_fit_index_error(test_str, MAX_INDEX) 19 | 20 | test_list = [0, 1, 2, 3] 21 | expect_cannot_fit_index_error(test_list, MIN_INDEX) 22 | expect_cannot_fit_index_error(test_list, MAX_INDEX) 23 | -------------------------------------------------------------------------------- /extra_tests/snippets/stdlib_traceback.py: -------------------------------------------------------------------------------- 1 | import traceback 2 | 3 | try: 4 | 1/0 5 | except ZeroDivisionError as ex: 6 | tb = traceback.extract_tb(ex.__traceback__) 7 | assert len(tb) == 1 8 | 9 | 10 | try: 11 | try: 12 | 1/0 13 | except ZeroDivisionError as ex: 14 | raise KeyError().with_traceback(ex.__traceback__) 15 | except KeyError as ex2: 16 | tb = traceback.extract_tb(ex2.__traceback__) 17 | assert tb[1].line == "1/0" 18 | 19 | 20 | try: 21 | try: 22 | 1/0 23 | except ZeroDivisionError as ex: 24 | raise ex.with_traceback(None) 25 | except ZeroDivisionError as ex2: 26 | tb = traceback.extract_tb(ex2.__traceback__) 27 | assert len(tb) == 1 28 | -------------------------------------------------------------------------------- /Lib/test/test_json/test_pass3.py: -------------------------------------------------------------------------------- 1 | from test.test_json import PyTest, CTest 2 | 3 | 4 | # from http://json.org/JSON_checker/test/pass3.json 5 | JSON = r''' 6 | { 7 | "JSON Test Pattern pass3": { 8 | "The outermost value": "must be an object or array.", 9 | "In this test": "It is an object." 10 | } 11 | } 12 | ''' 13 | 14 | 15 | class TestPass3: 16 | def test_parse(self): 17 | # test in/out equivalence and parsing 18 | res = self.loads(JSON) 19 | out = self.dumps(res) 20 | self.assertEqual(res, self.loads(out)) 21 | 22 | 23 | class TestPyPass3(TestPass3, PyTest): pass 24 | class TestCPass3(TestPass3, CTest): pass 25 | -------------------------------------------------------------------------------- /extra_tests/snippets/code_co_consts.py: -------------------------------------------------------------------------------- 1 | from asyncio import sleep 2 | 3 | def f(): 4 | def g(): 5 | return 1 6 | 7 | assert g.__code__.co_consts[0] == None 8 | return 2 9 | 10 | assert f.__code__.co_consts[0] == None 11 | 12 | def generator(): 13 | yield 1 14 | yield 2 15 | 16 | assert generator().gi_code.co_consts[0] == None 17 | 18 | async def async_f(): 19 | await sleep(1) 20 | return 1 21 | 22 | assert async_f.__code__.co_consts[0] == None 23 | 24 | lambda_f = lambda: 0 25 | assert lambda_f.__code__.co_consts[0] == None 26 | 27 | class cls: 28 | def f(): 29 | return 1 30 | 31 | assert cls().f.__code__.co_consts[0] == None 32 | -------------------------------------------------------------------------------- /Lib/test/xmltestdata/c14n-20/inC14N3.xml: -------------------------------------------------------------------------------- 1 | ]> 2 | 3 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_callable.py: -------------------------------------------------------------------------------- 1 | assert not callable(1) 2 | def f(): pass 3 | assert callable(f) 4 | assert callable(len) 5 | assert callable(lambda: 1) 6 | assert callable(int) 7 | 8 | class C: 9 | def __init__(self): 10 | # must be defined on class 11 | self.__call__ = lambda self: 1 12 | def f(self): pass 13 | assert callable(C) 14 | assert not callable(C()) 15 | assert callable(C().f) 16 | 17 | class C: 18 | def __call__(self): pass 19 | assert callable(C()) 20 | class C1(C): pass 21 | assert callable(C1()) 22 | class C: 23 | __call__ = 1 24 | # CPython returns true here, but fails when actually calling it 25 | assert callable(C()) 26 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_open.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | fd = open('README.md') 4 | assert 'RustPython' in fd.read() 5 | 6 | assert_raises(FileNotFoundError, open, 'DoesNotExist') 7 | 8 | # Use open as a context manager 9 | with open('README.md', 'rt') as fp: 10 | contents = fp.read() 11 | assert type(contents) == str, "type is " + str(type(contents)) 12 | 13 | with open('README.md', 'r') as fp: 14 | contents = fp.read() 15 | assert type(contents) == str, "type is " + str(type(contents)) 16 | 17 | with open('README.md', 'rb') as fp: 18 | contents = fp.read() 19 | assert type(contents) == bytes, "type is " + str(type(contents)) 20 | -------------------------------------------------------------------------------- /pylib/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython-pylib" 3 | version = "0.2.0" 4 | authors = ["RustPython Team"] 5 | description = "A subset of the Python standard library for use with RustPython" 6 | repository = "https://github.com/RustPython/RustPython" 7 | license-file = "Lib/PSF-LICENSE" 8 | edition = "2021" 9 | include = ["Cargo.toml", "src/**/*.rs", "Lib/", "!Lib/**/test/", "!Lib/**/*.pyc"] 10 | 11 | [features] 12 | freeze-stdlib = [] 13 | 14 | [dependencies] 15 | rustpython-compiler-core = { version = "0.2.0", path = "../compiler/core" } 16 | rustpython-derive = { version = "0.2.0", path = "../derive" } 17 | 18 | [build-dependencies] 19 | glob = { workspace = true } 20 | -------------------------------------------------------------------------------- /Lib/test/test_eintr.py: -------------------------------------------------------------------------------- 1 | import os 2 | import signal 3 | import unittest 4 | from test import support 5 | from test.support import script_helper 6 | 7 | 8 | @unittest.skipUnless(os.name == "posix", "only supported on Unix") 9 | class EINTRTests(unittest.TestCase): 10 | 11 | @unittest.skipUnless(hasattr(signal, "setitimer"), "requires setitimer()") 12 | def test_all(self): 13 | # Run the tester in a sub-process, to make sure there is only one 14 | # thread (for reliable signal delivery). 15 | script = support.findfile("_test_eintr.py") 16 | script_helper.run_test_script(script) 17 | 18 | 19 | if __name__ == "__main__": 20 | unittest.main() 21 | -------------------------------------------------------------------------------- /derive-impl/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rustpython-derive-impl" 3 | version = "0.2.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | rustpython-compiler-core = { path = "../compiler/core", version = "0.2.0" } 8 | rustpython-doc = { git = "https://github.com/RustPython/__doc__", branch = "main" } 9 | 10 | indexmap = { workspace = true } 11 | itertools = { workspace = true } 12 | once_cell = { workspace = true } 13 | syn = { workspace = true, features = ["full", "extra-traits"] } 14 | 15 | maplit = "1.0.2" 16 | proc-macro2 = "1.0.37" 17 | quote = "1.0.18" 18 | syn-ext = { version = "0.4.0", features = ["full"] } 19 | textwrap = { version = "0.15.0", default-features = false } 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/rfc.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: RFC 3 | about: Make a suggestion in a Request for Comments format to RustPython 4 | title: "[RFC] " 5 | labels: RFC 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Summary 11 | 12 | 13 | 14 | ## Detailed Explanation 15 | 16 | 17 | 18 | ## Drawbacks, Rationale, and Alternatives 19 | 20 | 21 | 22 | ## Unresolved Questions 23 | 24 | 25 | -------------------------------------------------------------------------------- /compiler/codegen/src/snapshots/rustpython_compiler_core__compile__tests__if_mixed.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/src/compile.rs 3 | expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pass\n\")" 4 | --- 5 | 1 0 LoadConst (True) 6 | 1 JumpIfFalse (4) 7 | 2 LoadConst (False) 8 | 3 JumpIfTrue (8) 9 | >> 4 LoadConst (False) 10 | 5 JumpIfFalse (8) 11 | 6 LoadConst (True) 12 | 7 JumpIfFalse (8) 13 | 14 | 2 >> 8 LoadConst (None) 15 | 9 ReturnValue 16 | 17 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_u_string_concat_2.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..17, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..17, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "Hello world", 16 | ), 17 | kind: Some( 18 | "u", 19 | ), 20 | }, 21 | }, 22 | }, 23 | }, 24 | ] 25 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_ord.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | assert ord("a") == 97 4 | assert ord("é") == 233 5 | assert ord("🤡") == 129313 6 | assert ord(b'a') == 97 7 | assert ord(bytearray(b'a')) == 97 8 | 9 | assert_raises(TypeError, ord, _msg='ord() is called with no argument') 10 | assert_raises(TypeError, ord, "", _msg='ord() is called with an empty string') 11 | assert_raises(TypeError, ord, "ab", _msg='ord() is called with more than one character') 12 | assert_raises(TypeError, ord, b"ab", _msg='ord() expected a character, but string of length 2 found') 13 | assert_raises(TypeError, ord, 1, _msg='ord() expected a string, bytes or bytearray, but found int') 14 | -------------------------------------------------------------------------------- /extra_tests/snippets/test_threading.py: -------------------------------------------------------------------------------- 1 | import threading 2 | import time 3 | 4 | output = [] 5 | 6 | 7 | def thread_function(name): 8 | output.append((name, 0)) 9 | time.sleep(2.0) 10 | output.append((name, 1)) 11 | 12 | 13 | output.append((0, 0)) 14 | x = threading.Thread(target=thread_function, args=(1, )) 15 | output.append((0, 1)) 16 | x.start() 17 | output.append((0, 2)) 18 | x.join() 19 | output.append((0, 3)) 20 | 21 | assert len(output) == 6, output 22 | # CPython has [(1, 0), (0, 2)] for the middle 2, but we have [(0, 2), (1, 0)] 23 | # TODO: maybe fix this, if it turns out to be a problem? 24 | # assert output == [(0, 0), (0, 1), (1, 0), (0, 2), (1, 1), (0, 3)] 25 | -------------------------------------------------------------------------------- /.gitpod.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM gitpod/workspace-full 2 | 3 | USER gitpod 4 | 5 | # Update Rust to the latest version 6 | RUN rm -rf ~/.rustup && \ 7 | export PATH=$HOME/.cargo/bin:$PATH && \ 8 | rustup update stable && \ 9 | rustup component add rls && \ 10 | # Set up wasm-pack and wasm32-unknown-unknown for rustpython_wasm 11 | curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh && \ 12 | rustup target add wasm32-unknown-unknown 13 | 14 | RUN sudo apt-get -q update \ 15 | && sudo apt-get install -yq \ 16 | libpython3.6 \ 17 | rust-lldb \ 18 | && sudo rm -rf /var/lib/apt/lists/* 19 | ENV RUST_LLDB=/usr/bin/lldb-8 20 | 21 | USER root 22 | -------------------------------------------------------------------------------- /Lib/unittest/test/__main__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import unittest 3 | 4 | 5 | def load_tests(loader, standard_tests, pattern): 6 | # top level directory cached on loader instance 7 | this_dir = os.path.dirname(__file__) 8 | pattern = pattern or "test_*.py" 9 | # We are inside unittest.test, so the top-level is two notches up 10 | top_level_dir = os.path.dirname(os.path.dirname(this_dir)) 11 | package_tests = loader.discover(start_dir=this_dir, pattern=pattern, 12 | top_level_dir=top_level_dir) 13 | standard_tests.addTests(package_tests) 14 | return standard_tests 15 | 16 | 17 | if __name__ == '__main__': 18 | unittest.main() 19 | -------------------------------------------------------------------------------- /compiler/codegen/src/snapshots/rustpython_codegen__compile__tests__if_mixed.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/codegen/src/compile.rs 3 | expression: "compile_exec(\"\\\nif (True and False) or (False and True):\n pass\n\")" 4 | --- 5 | 1 0 LoadConst (True) 6 | 1 JumpIfFalse (4) 7 | 2 LoadConst (False) 8 | 3 JumpIfTrue (8) 9 | >> 4 LoadConst (False) 10 | 5 JumpIfFalse (8) 11 | 6 LoadConst (True) 12 | 7 JumpIfFalse (8) 13 | 14 | 2 >> 8 LoadConst (None) 15 | 9 ReturnValue 16 | 17 | -------------------------------------------------------------------------------- /Lib/importlib/resources/__init__.py: -------------------------------------------------------------------------------- 1 | """Read resources contained within a package.""" 2 | 3 | from ._common import ( 4 | as_file, 5 | files, 6 | Package, 7 | ) 8 | 9 | from ._legacy import ( 10 | contents, 11 | open_binary, 12 | read_binary, 13 | open_text, 14 | read_text, 15 | is_resource, 16 | path, 17 | Resource, 18 | ) 19 | 20 | from .abc import ResourceReader 21 | 22 | 23 | __all__ = [ 24 | 'Package', 25 | 'Resource', 26 | 'ResourceReader', 27 | 'as_file', 28 | 'contents', 29 | 'files', 30 | 'is_resource', 31 | 'open_binary', 32 | 'open_text', 33 | 'path', 34 | 'read_binary', 35 | 'read_text', 36 | ] 37 | -------------------------------------------------------------------------------- /Lib/test/ann_module2.py: -------------------------------------------------------------------------------- 1 | """ 2 | Some correct syntax for variable annotation here. 3 | More examples are in test_grammar and test_parser. 4 | """ 5 | 6 | from typing import no_type_check, ClassVar 7 | 8 | i: int = 1 9 | j: int 10 | x: float = i/10 11 | 12 | def f(): 13 | class C: ... 14 | return C() 15 | 16 | f().new_attr: object = object() 17 | 18 | class C: 19 | def __init__(self, x: int) -> None: 20 | self.x = x 21 | 22 | c = C(5) 23 | c.new_attr: int = 10 24 | 25 | __annotations__ = {} 26 | 27 | 28 | @no_type_check 29 | class NTC: 30 | def meth(self, param: complex) -> None: 31 | ... 32 | 33 | class CV: 34 | var: ClassVar['CV'] 35 | 36 | CV.var = CV() 37 | -------------------------------------------------------------------------------- /extra_tests/snippets/builtin_str_subclass.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | x = "An interesting piece of text" 4 | assert x is str(x) 5 | 6 | class Stringy(str): 7 | def __new__(cls, value=""): 8 | return str.__new__(cls, value) 9 | 10 | def __init__(self, value): 11 | self.x = "substr" 12 | 13 | y = Stringy(1) 14 | assert type(y) is Stringy, "Type of Stringy should be stringy" 15 | assert type(str(y)) is str, "Str of a str-subtype should be a str." 16 | 17 | assert y + " other" == "1 other" 18 | assert y.x == "substr" 19 | 20 | ## Base strings currently get an attribute dict, but shouldn't. 21 | # with assert_raises(AttributeError): 22 | # "hello".x = 5 23 | -------------------------------------------------------------------------------- /extra_tests/snippets/syntax_del.py: -------------------------------------------------------------------------------- 1 | from testutils import assert_raises 2 | 3 | a = 1 4 | del a 5 | 6 | class MyObject: pass 7 | foo = MyObject() 8 | foo.bar = 2 9 | assert hasattr(foo, 'bar') 10 | del foo.bar 11 | 12 | assert not hasattr(foo, 'bar') 13 | 14 | x = 1 15 | y = 2 16 | del (x, y) 17 | assert_raises(NameError, lambda: x) # noqa: F821 18 | assert_raises(NameError, lambda: y) # noqa: F821 19 | 20 | with assert_raises(NameError): 21 | del y # noqa: F821 22 | 23 | # see https://github.com/RustPython/RustPython/issues/4863 24 | 25 | class MyTest: 26 | def __del__(self): 27 | type(self)() 28 | 29 | def test_del_panic(): 30 | mytest = MyTest() 31 | del mytest 32 | -------------------------------------------------------------------------------- /Lib/wsgiref/__init__.py: -------------------------------------------------------------------------------- 1 | """wsgiref -- a WSGI (PEP 3333) Reference Library 2 | 3 | Current Contents: 4 | 5 | * util -- Miscellaneous useful functions and wrappers 6 | 7 | * headers -- Manage response headers 8 | 9 | * handlers -- base classes for server/gateway implementations 10 | 11 | * simple_server -- a simple BaseHTTPServer that supports WSGI 12 | 13 | * validate -- validation wrapper that sits between an app and a server 14 | to detect errors in either 15 | 16 | To-Do: 17 | 18 | * cgi_gateway -- Run WSGI apps under CGI (pending a deployment standard) 19 | 20 | * cgi_wrapper -- Run CGI apps under WSGI 21 | 22 | * router -- a simple middleware component that handles URL traversal 23 | """ 24 | -------------------------------------------------------------------------------- /compiler/parser/src/snapshots/rustpython_parser__string__tests__parse_string_triple_quotes_with_kind.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: compiler/parser/src/string.rs 3 | expression: parse_ast 4 | --- 5 | [ 6 | Located { 7 | range: 0..20, 8 | custom: (), 9 | node: Expr { 10 | value: Located { 11 | range: 0..20, 12 | custom: (), 13 | node: Constant { 14 | value: Str( 15 | "Hello, world!", 16 | ), 17 | kind: Some( 18 | "u", 19 | ), 20 | }, 21 | }, 22 | }, 23 | }, 24 | ] 25 | -------------------------------------------------------------------------------- /wasm/demo/src/style.css: -------------------------------------------------------------------------------- 1 | textarea { 2 | font-family: monospace; 3 | resize: vertical; 4 | } 5 | 6 | #code, 7 | #console { 8 | height: 30vh; 9 | width: calc(100% - 3px); 10 | } 11 | 12 | .CodeMirror { 13 | border: 1px solid #ddd; 14 | height: 30vh !important; 15 | } 16 | 17 | #run-btn { 18 | width: 6em; 19 | height: 2em; 20 | font-size: 24px; 21 | } 22 | 23 | #error { 24 | color: tomato; 25 | margin-top: 10px; 26 | font-family: monospace; 27 | white-space: pre; 28 | } 29 | 30 | #code-wrapper { 31 | position: relative; 32 | } 33 | 34 | #snippets { 35 | position: absolute; 36 | right: 20px; 37 | top: 5px; 38 | z-index: 25; 39 | } 40 | --------------------------------------------------------------------------------